Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple select box support #65

Closed
shankhan opened this issue Sep 6, 2012 · 5 comments
Closed

Multiple select box support #65

shankhan opened this issue Sep 6, 2012 · 5 comments

Comments

@shankhan
Copy link

shankhan commented Sep 6, 2012

How does multiple select box work in rivets? Any example would be great

@aleemb
Copy link

aleemb commented Sep 23, 2012

Second that. Same problem has me stumped.

Any pointers would be very welcome.

@mikeric
Copy link
Owner

mikeric commented Sep 23, 2012

select-multiple inputs now work with the standard data-value binding in 0.3.10. Values should always be an array in this case — when the input changes, it will set the attribute with the array of selected values. Likewise, setting the attribute value to an array of selected values will update the select-multiple input's options accordingly.

@aleemb
Copy link

aleemb commented Sep 28, 2012

In the general use case most select boxes are (id, name) tuples where the ID is almost always a number.

Rivets.js expects to find a string so the following check fails where value is [1,2] and _ref is "1":

_results.push(o.selected = (_ref = o.value, __indexOf.call(value, _ref) >= 0));

It's better to check for bot strings and numbers (note: +_ref converts string to number):

_results.push(o.selected = (_ref = o.value, __indexOf.call(value, _ref) >= 0 || __indexOf.call(value, +_ref) >= 0));

I thought about converting IDs to a string array on the server side before passing it on to the client but that wouldn't be right since the JSON model representation wouldn't truly reflect the model. Since in HTML all attributes are considered strings whether you quote them or not, the model-view binder should handle it.

For now I have made the above change in my rivetsjs hoping it gets patched. If the patch doesn't get accepted, should I be looking to make the change in the adapter?

@aleemb
Copy link

aleemb commented Sep 28, 2012

Formatters are great! Just discovered their use through your other posting and will be using those in the interim.

@Tibar
Copy link

Tibar commented Aug 7, 2018

I know this post is old but how can I set a select to be a select-multiple and rivets recognizes that?

<select data-rv-value="building_vent.value" multiple="multiple" size="5" type="select-multiple">

That doesnt work ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants