Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not required condition returns error message "false" #214

Open
dangelion opened this issue Mar 6, 2014 · 1 comment
Open

Not required condition returns error message "false" #214

dangelion opened this issue Mar 6, 2014 · 1 comment
Labels

Comments

@dangelion
Copy link

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>"); } }

@chiefGui chiefGui added the bug label Jan 15, 2015
@platinumazure
Copy link

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.

See http://thedersen.com/projects/backbone-validation/#methods/prevalidate for more information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants