Unless I am missing something it appears that can-value in a containing does not work
-- choose--
one
two
one
two
and an associated map
data = new can.Map({
answer: “item1-1;item2.1”;
});
Does not work
Eliminating the and everything is OK
Not using is a really bad idea as IRL the list is long and items need to be logically grouped.
In addition I am masking the using the chosen-select jQuery plugin which slightly complicates things but makes for a much nicer interface
In an earlier version (no can-value) I explicitly managed all the selected attributes in the JS but I REALLY don’t want to have to hack that again. Problem has come to light in porting an older app to the latest canjs (originally written for canjs 1.x) and adopting recommended best practices etc
data = new can.Map({
answer: “item1-1;item2-1”;
});
Does not work
Eliminating the <optgroup> and everything is OK
Not using <optgroup> is a really bad idea as IRL the list is long and items need to be logically grouped.
In addition I am masking the <select> using the chosen-select jQuery plugin which slightly complicates things but makes for a much nicer interface
In an earlier version (no can-value) I explicitly managed all the selected attributes in the JS but I REALLY don’t want to have to hack that again. Problem has come to light in porting an older app to the latest canjs (originally written for canjs 1.x) and adopting recommended best practices etc
Thanks for the response but it seems to make no difference. This strikes me as an artefact of the binding whereby the targets are not being found (because the optgroup gets in the way) but that’s speculation on my part.
Also, unless I am completely misunderstanding - always possible - there is no need to specifically manage the ‘selected’ attribute in the <option>, it ‘just works’.
Surely that’s the point of 2-way binding …
When I first started with CanJS (couple of years ago or more) I was managing all the atributes like ‘checked/selected’ etc in the templates using the #if syntax but I’m trying to get away from all of that, and mostly succeeding.
The exceptions are this optgroup problem and checkboxes which are a pain in this respect. I’ve never found a satisfactory way of making 2-way binding work on checkboxes in such a way that a single atribute contains all the individual checked values (like a multiple select).
It seems to need code to make it work, again, perhaps I’ve missed something.