3

Attempt to clarify: In my Visualforce page I have 3 radio buttons and 2 text fields. If I select the first radio button automatically field 1 is shown and field 2 is hidden.

I select radio button 1 & field 1 and save into the database. When I edit the previously saved data, radio button 1 is not selected. How can I make it selected in edit mode?


 <apex:pageBlockSection columns="1" title="Shipping Information">
 <apex:selectRadio value="{!Quote__c.shipping_type__c}" onChange="show(this.value);">
 <apex:selectOption itemLabel="Use Store Settings" itemValue="0"  />
 <apex:selectOption itemLabel="Per Item" itemValue="1" />
 <apex:selectOption itemLabel="Fixed Price Per Order" itemValue="2"/>
 </apex:selectRadio>

     <apex:inputField value="{!Quote__c.storeprice__c}" id="defaultcost" style="display:block;"/>
     <apex:inputField value="{!Quote__c.price__c}" id="differcost" style="display:none;"/>
  </apex:pageBlockSection>


 <script>
  function show(t)
  {
   if ( t == 0 ){
    $('[id$="defaultcost"]').show();
    $('[id$="differcost"]').hide();
   }
   else{
    $('[id$="defaultcost"]').hide();
   $('[id$="differcost"]').show();

   }     
 }
  • 2
    what are you doing in onChange? – Pramod Kumar Apr 16 '14 at 13:20
  • @PramodKumar Based upon radio buttons i am showing/hideing the fields. – Sathya Apr 16 '14 at 13:24
  • Sathya -- would you be so kind as to reword your problem statement using more declarative language and perhaps numbered or bulleted points? The problem statement is not clear. – cropredy Apr 16 '14 at 15:45
  • Sathya -- your use of jQuery doesn't follow SFDC VF jQuery conventions - see developer.force.com/cookbook/recipe/… and specifically the $j = jQuery.noConflict(); – cropredy Apr 16 '14 at 17:40
  • @crop1645 where i want to do changes can you suggest me. – Sathya Apr 16 '14 at 19:31
1

Here is a simple construction that mirrors what you are trying to do

<apex:page standardcontroller="Foo__c" >
<apex:selectRadio value="{!Foo__c.RadioOptionVal__c}">
  <apex:selectOption itemLabel="Value 1" itemValue="1"/>
  <apex:selectOption itemLabel="Value 2" itemValue="2"/>
  <apex:selectOption itemLabel="Value 3" itemValue="3"/>
</apex:selectRadio>
</apex:page>

where Foo__c.radioOptionVal__c is a picklist with values '1', '2', '3'

  1. If I invoke the page using /apex/foo?id=someFooId ..
  2. VF will fetch the current value of radioOptionVal__c from the database ...
  3. If that value is a string of either '1', '2', or '3', then the proper radio button is defaulted. If the value in the database is null or something other than '1', '2', or '3', then no radio button is defaulted

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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