2

I have used the below component and I would like to show the "--None--". if the left side and right getting the no values. as a standard picklist feature.

Reference: How do I build a multi-select picklist UI in visualforce?

1 Answer 1

2

Picklists and multi-selct picklists that are built-into SF generally represent text strings. Using Apex, one can assign any value they want to a picklist field and it will be saved to that field even though it doesn't appear in the list. So, if you add "--None--" to your list of picklist values, it will simply show up as a string value of "--None--". If what you desire es to have a value of '' or isEmpty, isBlank, etc., generally the type of menu system that you've referenced won't do that unless the user moves everything into the left panel.

Perhaps the real question for you would be what does "--None--" accomplish for you in your data? Will having "--None--" appear work for you or do you need a "blank" value to appear in the picklist? You can always add any value you'd like to a picklist, including "--None--".

In the example given in in the blog referenced the post you linked to, A Multiselect Picklist Visualforce Component, the picklist was used in a VF page to select Contact records. In that situation, Id's may have been returned as opposed to strings. I didn't delve into all the details and know the solution can be used for many purposes. I also don't know how you intend to use it. If Id's will be involved, this kind of solution could be problematic as it doesn't act like a built-in SF picklist.

With that caveat, if you're using the code referenced as the answer in the post you linked to, you'll need to add an additional method for "--None--".

@AmatoreVitae posted an update to the controller code in his answer to the question that included the following:

// Parse &-separated values and labels from value and 
// put them in option
private void setOptions(SelectOption[] options, String value) {
    options.clear();
    String[] parts = value.split('&');
    for (Integer i=0; i<parts.size()/2; i++) {
        options.add(new SelectOption(EncodingUtil.urlDecode(parts[i*2], 'UTF-8'), 
          EncodingUtil.urlDecode(parts[(i*2)+1], 'UTF-8')));
    }
}

What you'll want to do is somehow modify the above method such that options[0] becomes --None--. You'll likely want to do that using the method below in the controller to add your --None-- to the cLeftOptions and associate it with '' (an empty string), assuming that's what you want associated with it.

public MultiselectController(){
    cLeftOptions=new SelectOption[]{};
    cRightOptions=new SelectOption[]{};
}//ENd init()

You'd want to call this method at the beginning of the controller class to add the --None-- select option. It could presumably also be called from your page.

Again, its important to understand this could be problematic depending on what object and fields the controller is bound to. It may be looking for object id's as opposed to strings. If that's the case, this kind of solution wouldn't be viable.

5
  • When you add the --None--, you need to add it to the left side, plus add a corresponding value to assign to it. That value can be "hidden" as an empty string. If you look at the class, you'll also see there are methods for left and right options hidden values. You may be able to make use of one of those methods as well. Perhaps that's what you're referring to?
    – crmprogdev
    Commented Mar 30, 2015 at 19:13
  • Depending on where you call it from and how you decide to invoke it, it should look something like SelectOption[0] = MultiselectController.cLeftOptions('--None--&``');. Note that you need the & to follow the --None-- and that the single quotes will need to be escaped. If that doesn't work, you may need to put a single space instead of a blank.
    – crmprogdev
    Commented Mar 30, 2015 at 19:41
  • How to hide the none when getting empty. because is this call dynamically?
    – Alex
    Commented Mar 30, 2015 at 19:44
  • You'll want to add an if statement that tests for that condition if you need it to be dynamic. If you want to rewrite the controller to satisfy all your needs and require more assistance with it, I recommend you create a new post that includes all your controller code stating where you're having difficulties or where you're stuck.
    – crmprogdev
    Commented Mar 30, 2015 at 20:38
  • i have created new salesforce.stackexchange.com/questions/70752/…
    – Alex
    Commented Mar 31, 2015 at 6:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .