0

I want to disable a multipicklist field, depending on other picklist field value.

if picklist__c is 'Inactive', then disable multipicklist__c. I used javascript but no luck.

document.getElementById('multipcklist').disable=true;

is not working.

I also tried :

document.getElementById("{!$Component.multipcklist}").disable=true;

still no luck.

please provide me any example so that i can implement the same in my vf page.

1
  • It's disabled rather than disable (e.g. myElement.disabled=true). The issue may be that you are not getting the element correctly. Have a look here to figure out how to start debugging your javascript. If you are still stuck then update your question to include the picklist field you are trying to disable and the how the javascript gets executed.
    – BarCotter
    Oct 1, 2014 at 12:20

3 Answers 3

2

You can achieve this as like below :

<apex:page controller="testListController">
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
<apex:form >
    <apex:inputField value="{!acc.CustomerPriority__c}" styleClass="first"/>
   <apex:inputField value="{!acc.testmulti__c}" styleClass="second"/>
</apex:form>
    <script>
$(document).on('change','.first',function(){
  console.log($('.second'));
$('.second').prop('disabled','disabled');
});

</script>
</apex:page>
10
  • 2
    In your answer you use JQuery, not only Javascript.
    – SF_user
    Oct 1, 2014 at 12:21
  • 1
    Thanks for reply. As i'm new to jquery can you please tell me how can i achieve this based on the picklist field values. If picklist__c is 'Inactive', i want to disable it. Oct 1, 2014 at 12:38
  • @SF_user We can bind event on select item for change event in javascript by using addEventListener but can't disable select list in an easy way so I used jquery. And problem was "Disable a multipicklist depending on other picklist value". This problem is solved by my answer :)
    – Eric
    Oct 1, 2014 at 12:42
  • 1
    I upvoted your answer because I think your answer is available !
    – SF_user
    Oct 1, 2014 at 12:57
  • 1
    @sales_lion You're back in the positive now ;) I did remove the last couple of lines from your answer though. On SFSE it's assumed that people will comment if something doesn't work, and accepting answers is a core mechanic of the site. You shouldn't ask people to do it!
    – Matt Lacey
    Oct 1, 2014 at 23:50
0

Try with disabled (with a 'd'), like this :

document.getElementById('{!$Component.multipcklist}').disabled=true;
4
  • No luck. Can you please provide me any example, that is working. It may help me alot. Just a small example to disable the multipicklist.@SF_user Oct 1, 2014 at 12:07
  • And if you replace " by ' ? (I edited my answer).
    – SF_user
    Oct 1, 2014 at 12:10
  • document.getElementById('{!$Component.multipcklist}').disabled=true; should work, once the getElementById is actually returning an element.
    – BarCotter
    Oct 1, 2014 at 12:29
  • Yes, obviously it works only if the getElementById returns something :) !
    – SF_user
    Oct 1, 2014 at 12:31
-1

As per the Question the Picklist values you are referring to should control display of second picklist field(multi-select).

We can achieve this using javascript, JQuery, ActionFunction, ActionSupport.

As part of Maintenance: The Question comes what to use when, for ex: What if the picklist values of the first picklist changes in the future? If we use javascript or Jquery we need to change the code as per the changed values every time using these values in a string array.

What I think as better solution is using Action support Tag to act on changing the values in picklist and a custom settings object with values in picklist1 for which the second picklist field has to get disabled. use this custom settings object in controller to update a boolean variable true or false and use it in second picklist tag to hide.

So, when ever the values in first picklist field changes, you can update the custom settings with those values so that you no need to change the code every time.

If the first picklist field values not gonna change then its always good to go with client side scripting using javascript or JQuery to implement as given above.

You must log in to answer this question.

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