Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

I am using apex:selectList component and trying to make it readonly by setting its readonly property like below -

<apex:selectList value="{!state}" multiselect="false" size="1" id="state" readonly="true">
<apex:selectOptions value="{!stateOptions}"/> 
</apex:selectList> 

I am setting its value using one javascript function dynamically something like below -

document.getElementById('j_id0:frm:j_id10:j_id21:pbtCostDetails:state').value = 'Jaipur';

problem is it is not getting readonly. User is able to select any value in select list.

Thanks

share|improve this question
    
If I recall correctly it's nothing wrong with Visualforce, it's the <select> HTML tag that's bit quirky to use. Check stackoverflow.com/questions/1191113/… or stackoverflow.com/questions/368813/readonly-select-tag, inspect the generated HTML in the browser... –  eyescream Dec 17 '13 at 9:11
add comment

1 Answer 1

up vote 5 down vote accepted

There is some difference between readonly and disabled parameters.

If you want to show the picklist visually as disabled on the page you need to use disabled="true" parameter.

If you want, that selected value will not transmitted to the controller you need to use readonly="true".

Here is a test page. Just testing it.

<apex:pageBlock mode="edit" title="Selection" tabStyle="Account">
    <apex:pageBlockButtons>
        <apex:commandButton value="Submit"/>
        Selected Value:<apex:outputText value="{!output}"/>
    </apex:pageBlockButtons>

    <apex:pageBlockSection columns="1" showHeader="false" collapsible="false">
        <apex:outputLabel value="Select:" for="state"/>    
        <apex:selectList value="{!output}" multiselect="false" size="1" id="state" readonly="true">
            <apex:selectOption itemLabel="Option 1" itemValue="Option 1"/>
            <apex:selectOption itemLabel="Option 2" itemValue="Option 2"/>
        </apex:selectList>

    </apex:pageBlockSection>
</apex:pageBlock>

1) Readonly = true
After submition the value from the picklist is not transferred to the controller. enter image description here

2) Readonly = false
The value successfuly transferred. enter image description here

2) Disabled = true
The picklist is completely disabled.

enter image description here

share|improve this answer
    
As per your reply, in both the cases "disabled" and "readonly" values don't submit to controller. but i read somewhere that in case of "disabled" value doesn't get transferred to controller but in case of "Readonly" values get transferred to controller. Can you please confirm? –  Pramod Kumar Dec 17 '13 at 11:11
    
It is not directly documented (is it?). The documentation says: If set to true (readonly), the list option selections cannot be changed. I've tried it on my dev org and if readonly is set to true then i cannot get the selected value in controller. –  mast0r Dec 17 '13 at 12:15
    
I am not sure about the salesforce specifically. but html code work like this. "ReadOnly" gets submitted to server but "Disabled" doesn't. I am not sure then where should i use "Readonly=true" property. –  Pramod Kumar Dec 17 '13 at 13:47
    
@PramodKumar I think just use disabled and you are on the right way. –  mast0r Dec 17 '13 at 14:38
    
You are right. Thanks a lot –  Pramod Kumar Dec 17 '13 at 14:55
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.