[SalesForce] Disabled fields having values are cleared on click of save when other mandatory fields are not entered

My doubt is :
I have custom vf page for account object . I have few disabled fields in that page whose values will be populated based on autocomplete field selection using jquery autocomplete widget. I have few other mandatory fields after the disabled fields.

Test scenario :

  1. I will select one value from autocomplete field which will populate the disabled fields.
  2. I will not fill the mandatory fields . On click of save error for mandatory fields is thrown but it is clearing the disabled field values. Eventhough i am using some hidden fields to store the values of disabled fields it doesnt help.

Any solution how to keep the values intact in disabled fields will be of great help. Let me know if i am not clear ,i can explain the doubt if required.

Best Answer

If your inputs are anyway hidden you can use just a normal html fields to output/show the selected values and use hidden fields to assign values to use in controller.

<script>
    function someFunction(){
        jQuery('[id$=myVar1Hidden], #myVar1Output').val(value1);
    }
</script>

<!-- This will be used to pass the variable to the controller -->
<apex:inputHidden value="{!myVar1}" id="myVar1Hidden" />

<!-- This is only to show the selected value to the user on the page -->
<input type="text" id="myVar1Output" value="" disabled="disabled" />
Related Topic