1

I need to disable a multi select picklist field (inputField) in the visualforce page on page load and enable it on button click.

I tried using javascript. It worked fine for other inputFields but did work out for multi select picklist field.

JS Code i used is below

function onPageLoad(){
        document.getElementById('page:frm:pb:pbs:test').readOnly = true;     
}
window.onload = onPageLoad;
    function onEdit(){
        document.getElementById('page:frm:pb:pbs:test').readOnly = false;    
    }
4
  • Could you try use "document.getElementById('page:frm:pb:pbs:test').disabled= true;" Commented Mar 9, 2015 at 13:49
  • tried that too!.. It still did not work for multiselect picklist Commented Mar 9, 2015 at 13:56
  • Don't get mad with disabling! Just hide the picklist if you don't need it. Commented Mar 9, 2015 at 14:18
  • Thanks.. I just hid the picklist.. as neither disabled nor readonly attribute worked Commented Mar 9, 2015 at 16:31

2 Answers 2

1

Try this i am sure this will work for you.

function onPageLoad(){
    document.getElementById('page:frm:pb:pbs:test__unselected').disabled = true;
    document.getElementById('page:frm:pb:pbs:test__selected').disabled = true;  
}
window.onload = onPageLoad;
function onEdit(){
    document.getElementById('page:frm:pb:pbs:test__unselected').disabled = false;
    document.getElementById('page:frm:pb:pbs:test__selected').disabled = false; 
}
0
0

I accomplished this via a little bit of jQuery, here is where I'm setting up some inputfields (should be workable with a single element too):

<apex:repeat value="{!fsList}" var="f">
    <apex:inputField id="inputFld" styleClass="inputFld" value="{!sobjectRecord[f]}"/>
</apex:repeat>

At the bottom I set this up:

<apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js" />
<script>
var j$ = jQuery.noConflict();
j$(document).ready(function(){
    j$('.inputFld').prop('disabled',{!fldsDisabled});});
</script>

This approach worked very nicely. I have boolean within my controller that I'm able to dynamically enable/disable when the edit button is clicked it is set to false.

You must log in to answer this question.

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