javascript - backbone relational validate related field -
I am using spinal cord with the DEGENGO TISSPEE and I have a problem in the verification relationship.
We say, I have an original model with valid method:
MyModel = Backbone Relational model. Extension ({urlRoot: '/ api / v1 / sampleNameDel /', relation: [{type: backbone hace, key: 'box', related model: 'boxmodel', INCLUDED INJSON: 'id'}], validate: Function (attr.name) {console.log ('attry name verification failed'); Return "Sea Monster! Name is required!";} (! Attr.box) {console.log ('etr Box validation failed '); console.log (attr.box); return "no no! You forgot to set up the box!";}}});
In some scenarios, I am creating a new MyModel instance with the box
as the resource of another object:
var BoxUri = '/ API / V1 / box / 3' var pnmodel = new mimodel (); NewModel.set ('Box', BoxUri); NewModel.set ('name', 'new name for model');
And here's the meritum ... when I do save
on the model, it is always the attr.box
verification and Attr.box
is none
- even when all fields are set correctly.
What if, in the valid
function, do something like:
validate: function (attr) {if (! Attr.name ) {Console.log ('entry name verification failed'); Return "Si Mon!" Is essentially sarsly! "; } Console.log (attr.box); }
In the above case, the attr.box
console is displayed in the form of the desired object.
Of course, if I remove the verification method, the object is saved with the correct relation and so on.
I'm red in the documentation, by default, validation is only going on when calling save ()
, so all the fields are already set. So how (and why) the verification
function knows that attr.box
is empty?
Or maybe my view is just wrong?
You are setting the value in the wrong object:
var box URI = '/ API / V1 / box / 3' var pnmodel = new mimodel (); NewModel.set ('Box', BoxUri); // Mimodel Pneumodel.Set ('name', 'new name for model') instead of New Model;
By the way, related model: 'boxmodel',
to related model: box modell,
Comments
Post a Comment