backbone.validation icon indicating copy to clipboard operation
backbone.validation copied to clipboard

When using the same model with multiple views binding specific options propogate to all view instances

Open benmccormick opened this issue 9 years ago • 0 comments

I have 2 views bound to the same model where I want to set different options to each validation binding.

Specifically I want to use different validation callbacks since I have a nested model (a "list item" that contains a sublist of "list items" basically). I want the sublist items to have different validation rules so that the top level "list" view doesn't select the sublist items as well as the top level rule items.

In terms of code I expected in the example that the 'valid' function for view 1 in the example below

options1 = {valid:fn1};
options2 = {valid:fn2};

view1 = new Example1View({model:model})
view2 = new Example2View({model:model})

Validation.bind(view1, options1);
Validation.bind(view2, options2);

would result in fn1 being called. But it turns out that its actually fn2, because the options are mixed into the model, not the view. That's super unclear, and not really what you'd want (since the valid/invalid callbacks, attributes and selector properties in particular are more view specific than model specific).

This may be baked too deeply into the code to do anything about (as somebody unfamiliar with the codebase, I didn't see a simple solution to create a PR with, but its probably at least worth clarifying in the documentation).

benmccormick avatar Mar 05 '15 21:03 benmccormick