Closed shivarambodumalla closed 8 years ago
Hi @shivarambodumalla ,
you could do something like this:
var sol = $('#mySelect').searchableOptionList({
/* options omitted */
});
// later
var selectedOptionsAsArray = sol.getSelection();
This will not give you the internal data structure but the actual selected checkboxes/radios instead.
Let me know if that helped you.
Cheers
Patrick
Hi, How can I get the internal values, I don't want the checkbox container thank you
Hi @ikramcheb,
the internal data structure is attached to the input as sol-item
data attribute so you could do this to convert the inputs to an array of the internal data representation:
var asInputs = sol.getSelection(),
asInternalRepresentation = [];
// iterate over the selected items/dom elements
// extract the 'sol-item' data from it and store it in the other array
for (var i = 0; i < asInputs.length; i++) {
asInternalRepresentation[i] = asInputs[i].data('sol-item');
}
Hi, I got the following error TypeError: asInputs[i].data is not a function Noting that sol.getSelection() returns an array of inputs, so the problem is how to extract the 'sol-item'
I thought I was returning jQuery objects but according to your error message it seems to be plain DOM elements then. The solution then is to wrap the object with jQuery again so
var asInputs = sol.getSelection(),
asInternalRepresentation = [];
// iterate over the selected items/dom elements
// extract the 'sol-item' data from it and store it in the other array
for (var i = 0; i < asInputs.length; i++) {
// change this
// asInternalRepresentation[i] = asInputs[i].data('sol-item');
// to this
asInternalRepresentation[i] = $(asInputs[i]).data('sol-item');
}
should do the trick. Let me know if this worked.
Cheers
yes thanks, just add label $(asInputs[i]).data('sol-item').label
HI i was trying to get the selected values in to an arry will you please help me how to get them ....