gmac / backbone.epoxy

Declarative data binding and computed models for Backbone
http://epoxyjs.org
MIT License
615 stars 89 forks source link

Validating text values #133

Open docmattman opened 8 years ago

docmattman commented 8 years ago

I am binding a text input to a model property. When the value changes, I want to save the changes to the server. I have this part done already. However, I need to run some validation on the new value before saving the model. Mostly I want to make sure that the text input isn't empty.

The general idea I'm working on is changing the title of the model in the view. I want to make sure that the new title isn't empty before saving the model back to the server. I have validation set on the server, but I would like to avoid wasting an ajax call to the server, since I already know empty values won't work.

How can I accomplish some simple validation like this when binding form elements to the model?

docmattman commented 8 years ago

Bump?

jekuno commented 8 years ago

Have a look at Backbone.Validation for this and bind the validate call to e.g. a change event of the according input field(s).