Disabled Items / Preload Items #476

Closed
wants to merge 2 commits into
from

Projects

None yet

3 participants

@todd-givainc

With the following changes, Giva, Inc. ( http://givainc.com/ ) has added:

  • Ability to preload data into the multiple select field.
  • Ability to have a disabled item in the select field (from both preloaded data and selected data)

JSFiddle Example:
http://jsfiddle.net/ehBU4/4/

todd-givainc added some commits Oct 8, 2012
@todd-givainc todd-givainc preloadSelections patch
Added the ability to preload default items in select2 multiple.
d865ac3
@todd-givainc todd-givainc preloadSelections functionality
Added the ability to disable selections.
4d6f1a4
@dswitzer

+1

@todd-givainc

@ivaynberg - Any feedback on this? Thanks.

@todd-givainc

Closing, removing the preload change as you can do the same thing with 'data:' - Will modify it the disabled options to work with the existing data function. Will submit a new pull requests when I've completed this.

@ivaynberg

instead of "disabled" lets call it "locked", disabled is meant for items that show up in the list but cannot be selected - like in the option disabled='true' attribute.

@todd-givainc

I can certainly change that. After looking things over, it seems that preload is still relevant because data doesn't kick off for a multi-select.

@ivaynberg

preload should be handled by initSelection...

@todd-givainc

Then, there's a bug. If you consider the following:
http://jsfiddle.net/webRat/kZb8U/1/

It fails to load anything. If I comment out line 1944 & 1954 in the main select2.js file, this preloads just fine.

@ivaynberg

i dont think thats a bug. your input field doesnt specify any value so select2 doesnt think there is anything to initialize... if you add value="0" attribute to the input tag it works fine.

for your usecase you can call data after your init select2

@todd-givainc

My input field shouldn't have any value because I'm attempting to 'preload' data.

You pointed me in the direction of initSelection (note, 3 comments above):
"preload should be handled by initSelection..."

And, I attempted that which is why I said it's a bug / issue. If preloading data should indeed be handled by initSelection, then initSelection needs to accept the fact of the possibility that value is empty.

I do acknowledge that $(element).select2("data", preload_data) does work. I'll go that route and make a pull for the locked items instead.

@ivaynberg

why would the control have preloaded data if it has no values for such data specified in the tag?

when you want to preselect data in a select you specify the options as selected. same idea with the input tag, set the value to the ids of the items that should be preselected.

@todd-givainc

My thought was that the initSelection should populate the hidden form field because I'm using it to preload data and preload the selections.

Coworker clarified your thoughts a little via IM and actually gave me a reason why we'd want the hidden form field populated manually (in case for whatever reason, select2 doesn't initialize properly, at least the form will still work)

For clarity's sake, @ivaynberg is talking about this:
http://jsfiddle.net/kZb8U/5/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment