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

Add support to _text attributes of multi-select boxes

Open spiegela opened this issue 13 years ago • 3 comments

The title (and commit message) kind of speak for themselves. I have some multi-select boxes, and without this patch, the "_text" attribute is pretty useless.

For example, with the view:

      <select id='multiple_select' multiple='true'>
        <option value='selection_1'>Selection 1</option>
        <option value='selection_2'>Selection 2</option>
      </select>

with both of these selected you'll have an attribute like:

model.multiple_select
 -> ["selection_1", "selection_2"]
model.multiple_select_text
 -> "Selection 1Selection 2"

With my patch, things will work more appropriately:

model.multiple_select
 -> ["selection_1", "selection_2"]
model.multiple_select_text
 -> ["Selection 1", "Selection 2"]

Hooray!

Specs are included, let me know what you think!

spiegela avatar Jan 14 '12 20:01 spiegela

@spiegela there's another pull request that we're getting ready pull in, and it is going to get rid of the _text attribute for select boxes. We didn't really see a need for them.

Can you explain how you use the _text attribute in your app and why it's a benefit. We'll keep the _text attribute if people are using it.

paulyoder avatar Jan 14 '12 21:01 paulyoder

The _text attributes make things convenient for me. In my app, I have a set of views that create a back-end query. It also sets up other views for displaying that query. I am planning to use the "value" of the select box for the query, and the "_text" attribute for views, with the human-readable version.

Of course, without this feature, there are other ways to do this -- like make the selection value be an index of a collection, but this way is nice and easy.

Thanks!

spiegela avatar Jan 15 '12 04:01 spiegela

still not sure what we should do with this...

can you explain your scenario a little further, @spiegela? I'm not sure i understand why you need the _text value.

I know when I originally wrote the code that uses _text, it was because I wasn't using Backbone correctly. I was using it to pull values from the select box and populate my model before sending it back to the server. What I should have done, was send all of the data back to the server and have the server respond with a _text version of the value, instead of relying on the client side code to track that.

Is there a way for you to do something like this, or is it really going to be that much easier for you to have a _text attribute for your select boxes?

mxriverlynn avatar Jan 31 '12 20:01 mxriverlynn