[SalesForce] How to disable input text without losing its value when page is reloaded after validation failure

I have a apex:inputText field which is disable in following 2 ways

  1. <apex:inputText Id="pBSId" value="{!pBSId}"  disabled="true"/>
      <apex:image value="/s.gif" StyleClass="lookupIcon" style="cursor:pointer;" onclick="openLookupPopup();"/> 

or

  2. <apex:inputText Id="pBSId" value="{!pBSId}" />
     <apex:image value="/s.gif" StyleClass="lookupIcon" style="cursor:pointer;" onclick="openLookupPopup();"/> 
        <script>document.getElementById('{!$Component.pBSId}').disabled =true; </script> 

by using lookup i was passing values to this field.But manually user can not edit values.

The only problem i was facing is when any validation fails in controller it will through error messages to visual force pages.At this time all field values which were entered previously were holding, but this field is loosing it's old value and displaying empty field.But if i rempve disable(true) it is holding value.

I was wondering is there any way to achieve these two,like have to hold previous value and to disable the field from any manual edits other than selecting from lookup window.
enter image description here

Best Answer

you can use html-readonly="true" to make inputText as disable and also pass value to server side.

Related Topic