You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
I have these conditions on a field: minLength: 3 required: false
Example 1: If I enter two characters it correctly shows error message "must be at least 3 characters"
Example 2: Now I let the field empty but it shows error message: "false" ==> that's the issue. Here the field must be valid because it's not required
How can solve?
I validate each field with this function on event change: function(event) { var errMsg, input, inputName, inputValue; input = $(event.currentTarget); inputName = event.currentTarget.name; inputValue = input.val(); errMsg = this.model.preValidate(inputName, inputValue); if (errMsg === "") { input.removeClass("error"); input.addClass("valid"); return input.parent(".form-group").find(".error-msg").remove(); } else { input.parent(".form-group").find(".error-msg").remove(); input.removeClass("valid"); input.addClass("error"); return input.parent(".form-group").append("<span for='" + inputName + "' class='error-msg'>" + errMsg + "</span>"); } }
The text was updated successfully, but these errors were encountered:
Are you sure you should be comparing errMsg === ""? The only thing promised in the preValidate() contract is that falsy is returned if no validation errors are present and a truthy error object (or array) is returned if there are validation errors.
Try changing the statement to if (!errMsg) and see if that fixes your issue.
Hi,
I have these conditions on a field:
minLength: 3 required: false
Example 1: If I enter two characters it correctly shows error message "must be at least 3 characters"
Example 2: Now I let the field empty but it shows error message: "false" ==> that's the issue. Here the field must be valid because it's not required
How can solve?
I validate each field with this function on event change:
function(event) { var errMsg, input, inputName, inputValue; input = $(event.currentTarget); inputName = event.currentTarget.name; inputValue = input.val(); errMsg = this.model.preValidate(inputName, inputValue); if (errMsg === "") { input.removeClass("error"); input.addClass("valid"); return input.parent(".form-group").find(".error-msg").remove(); } else { input.parent(".form-group").find(".error-msg").remove(); input.removeClass("valid"); input.addClass("error"); return input.parent(".form-group").append("<span for='" + inputName + "' class='error-msg'>" + errMsg + "</span>"); } }
The text was updated successfully, but these errors were encountered: