Sunday, 15 May 2011

backbone.js - Backbone validation of complex object property (momentjs) -



backbone.js - Backbone validation of complex object property (momentjs) -

i'm using momentjs object in model:

var mymodel = backbone.model.extend({ defaults: { iamstring: "hello", iamdate: moment() }, validation: { iamstring: { required: true, fn: function (value, attr, computedstate) { alert('validation of iamstring called!'); } }, iamdate: { required: true, fn: function (value, attr, computedstate) { alert('validation of iamdate called!'); } } }, print: function () { homecoming this.get('iamstring') + ' ' + this.get('iamdate').format('yyyy-mm-dd hh:mm:ss'); } });

if update model, iamstring validation getting called, iamdate validation never getting called.

here jsfiddle sample. how can create iamdate validation possible?

if phone call moment() function, must add together format.

$('#validate').click(function () { mymodel.set({ iamstring: 'bye bye', iamdate: moment('2014-05-05 12:12:12').format('yyyy-mm-dd hh:mm:ss') }, { validate: true }); alert(mymodel.print()); });

validation backbone.js momentjs

No comments:

Post a Comment