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

Easy to to get list of invalid form fields #16

Open
scottcorgan opened this issue Nov 5, 2014 · 2 comments
Open

Easy to to get list of invalid form fields #16

scottcorgan opened this issue Nov 5, 2014 · 2 comments

Comments

@scottcorgan
Copy link

Ran into an issue recently with an invalid form field preventing the form from submitting. Right now an invalid class is added to an element, but it would be nice to have a method on the class to get a list of invalid form fields.

var invalidFields = formView.invalidFields();
@cdaringe
Copy link
Member

@scottcorgan, simple enough. You can extend with something like

invalidFields: function() {
    return this._fieldViewsArray.filter(function(field) {
        return !field.valid;
    });
};

will that work for ya?

@maddijoyce
Copy link

I went a different way and changed the setValid function so validCallback gets a second parameter:

setValid: function (now, forceFire) {
  var prev = this.valid;
  this.valid = now;
  if (prev !== now || forceFire) {
    this.validCallback(now, _.mapValues(this._fieldViews, 'valid'));
  }
},

Now, my valid callback gets:

  • A Boolean- Whether everything is valid or not.
  • An Object- Keys are input names and values are valid or not, e.g. { 'firstName': true, 'lastName': false }

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

No branches or pull requests

4 participants