Backbone Form Validation on type -


i wondering if there clean way in backbone validate forms type without using plugin. issue if have user model with: name, surname, email... can validate model whole not each model attribute individually.

example:

var user = backbone.model.extend({ validate: function(attrs) {   if(!attrs.name) return "name not set" }  var userview = backbone.view.extend({   events: { 'keyup input' : 'validateinput' },   validateinput: return this.model.isvalid()  }) 

one generic method can use :

events: {     'keyup input': 'validatefeild' }, validatefeild: function (event) {     var value = event.currenttarget.value;     var validator = $(event.currenttarget).attr('validator');     console.log(validator);     // utils.validate(value, validator); here can manage validation in separate utility class } 

and in html have :

<input id="label" type="text" validator="required" /> 

here's full example


Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -