powmedia / backbone-forms

Form framework for BackboneJS with nested forms, editable lists and validation
MIT License
2.17k stars 415 forks source link

Form.Editor.validate() reads all form values for nothing #518

Open sniederb opened 8 years ago

sniederb commented 8 years ago

Backbone.Form.Editor.validate() has the lines ...

var formValues = this.form ? this.form.getValue() : {},
...
error = getValidator(validator)(value, formValues);

However, all validators only have the signature function(value)

As form validation calls editor.validate() for each editor, and then each editor build the entire form value model, the superfluous this.form.getValue() creates O(n^2) calls for nothing.

fonji commented 8 years ago

I actually use formValues in my custom validators... A solution would be to pass the editor to the validator, then the validator can call editor.form.getValue() if necessary. It would also offer access to the editor's config, which might be useful.

sniederb commented 8 years ago

fonji, I really like that idea. Would be great to see that change soon.