Skip to content

Commit

Permalink
use internal flag
Browse files Browse the repository at this point in the history
  • Loading branch information
ej2015 committed May 30, 2019
1 parent 722124e commit 2415b60
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 22 deletions.
24 changes: 8 additions & 16 deletions dist/simple-react-validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function () {
},
element: function element(message, options) {
var element = options.element || this.parent.element;
return element(message, options.className, options.id, options.display);
return element(message, options.className);
},
numeric: function numeric(val) {
return this.testRegex(val, /^(\d+.?\d*)?$/);
Expand Down Expand Up @@ -132,6 +132,7 @@ function () {
});

this.fields = {};
this.visibleFields = _options.onBlur || [];
this.errorMessages = {};
this.messagesShown = false;
this.rules = _objectSpread({
Expand Down Expand Up @@ -393,12 +394,8 @@ function () {
return message;
};
} else {
this.element = function (message, className, id, display) {
this.element = function (message, className) {
return React.createElement('div', {
style: {
display: display
},
id: id,
className: className || _this.className || 'srv-validation-message'
}, message);
};
Expand All @@ -424,12 +421,7 @@ function () {
key: "showMessage",
value: function showMessage(field) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var id = "".concat(field, "-validator");
var ele = document.getElementById(id);

if (ele) {
ele.style.display = "block";
}
this.visibleFields.push(field);
}
}, {
key: "allValid",
Expand Down Expand Up @@ -507,10 +499,10 @@ function () {
}

this.errorMessages[field] = message;
var display = this.messagesShown ? 'block' : 'none';
options['display'] = display;
options['id'] = "".concat(field, "-validator");
return this.helpers.element(message, options);

if (this.messagesShown || this.visibleFields.includes(field)) {
return this.helpers.element(message, options);
}
}
}
} catch (err) {
Expand Down
Loading

0 comments on commit 2415b60

Please sign in to comment.