You need to sign in to do that
Don't have an account?

Multi select field in visualforce page
Hi All,
We have a multi select html field where users can do CTRL + select multiple values, this should be stored in a multi select field.
<div class="form-group">
<label class="control-label label-form" for="Attrib">Attrib<span class="mandatory"> *</span></label>
<div class="input-group">
<div class="input-group-addon">
<span class="glyphicon glyphicon-pencil" aria-hidden="true"/>
</div>
<select multiple="multiple" class="form-control">
<option>Colour</option>
<option>Shape</option>
<option>Size</option>
<option>Weight</option>
</select>
</div>
</div>
How can I store the above selected values in a multi select field?
Thanks,
Prasanna
We have a multi select html field where users can do CTRL + select multiple values, this should be stored in a multi select field.
<div class="form-group">
<label class="control-label label-form" for="Attrib">Attrib<span class="mandatory"> *</span></label>
<div class="input-group">
<div class="input-group-addon">
<span class="glyphicon glyphicon-pencil" aria-hidden="true"/>
</div>
<select multiple="multiple" class="form-control">
<option>Colour</option>
<option>Shape</option>
<option>Size</option>
<option>Weight</option>
</select>
</div>
</div>
How can I store the above selected values in a multi select field?
Thanks,
Prasanna
As you can see, we are calling javascript method namely pressButton() on click of the button. In that function, we are using a jquery iterator to fetch all the selected options from the picklist. I have given Id to picklist namely 'selectId' at line no.36 and then referencing its selected options and concatenating them in ';' separated format and atlast assigning this concatenated value to 'allSelected' variable. If you have multiple such select components on your page, give Id to each component and then do the below:
Here for understanding purpose, I have given picklist Id as selectId1, selectId2...so on and respective selected values are being hold in variables namely picklist1, picklist2...so on. Atlast of every iteration, call an action function and pass all these concatenated values to controller in one go. Please let me know if this explanation enough for you to accomplish your task.
All Answers
If you just want to display the selected values in comma separated values then you can use Javascript:
https://developer.salesforce.com/forums/ForumsMain?id=906F0000000BaMqIAK
Thanks for your response.
I want to send the selected values to the controller.
Thanks,
Prasanna
Here callActionFunc is the name of the actionFunction which we using to call controller's method and passing semi colon separated value to controller.
couple of quesitons. From the bootsctap code above, how will I call the function: collectValues?
Is callActionFunc a function in the controller?
Thanks,
Prasanna
To answer your questions, you will have to call this method on click of button to form a string separated by '; ' and atlast an action function will be called to pass this value to controller. Please refer below mentioned code to achieve this. This is working fine in my org:
Can you please explain how the selected values are passed in to the function?
Actually I have several such fields in the page and I have a final submit button at the footer, thus I cannot have button for each of fields, So I need to capture the selected values to a string or something like that and then when I press submit button at the end, I will have to pass all the values for each of the concatenated string. (1 concatenated string for each field)
Would be helpful if you can help me understand how values are passed in to the function pressButton()
Thanks again.
As you can see, we are calling javascript method namely pressButton() on click of the button. In that function, we are using a jquery iterator to fetch all the selected options from the picklist. I have given Id to picklist namely 'selectId' at line no.36 and then referencing its selected options and concatenating them in ';' separated format and atlast assigning this concatenated value to 'allSelected' variable. If you have multiple such select components on your page, give Id to each component and then do the below:
Here for understanding purpose, I have given picklist Id as selectId1, selectId2...so on and respective selected values are being hold in variables namely picklist1, picklist2...so on. Atlast of every iteration, call an action function and pass all these concatenated values to controller in one go. Please let me know if this explanation enough for you to accomplish your task.