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

Comments

Projects
None yet
4 participants
@scottcorgan

scottcorgan commented Nov 5, 2014

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();

@bear bear added the enhancement label Nov 6, 2014

@cdaringe

This comment has been minimized.

Show comment
Hide comment
@cdaringe

cdaringe Mar 25, 2015

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?

Member

cdaringe commented Mar 25, 2015

@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

This comment has been minimized.

Show comment
Hide comment
@maddijoyce

maddijoyce Jul 22, 2015

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 }

maddijoyce commented Jul 22, 2015

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