1

Picklist 1 values: Yes No

Picklist2 values:

one two three

I was able to attain the rerendering functionality from the below sample code. If I select picklist1 value as "yes", I am able to display picklist2. And now if I select picklist2 value as "three" and change picklist1 value to "No", Picklist2 value is disappeared from the page, so far so good. Now when I change the Picklist1 value back to "Yes", the Picklist2 value is rerendered on page with value as three. I want to reset the Picklist2 value to none. I need similar funtionality to be implemented with all the text and other fields. Any help is much appreciated.Thanks.

Vfpage

<apex:pageblockSectionItem> <apex:inputfield value="{!picklist1}" onchange="reset();"> </apex:pageblockSectionItem>

<apex:pageblockSectionItem rendered = "{!value}"> <apex:inputfield value="{!picklist2}"> </apex:pageblockSectionItem>

<apex:actionfunction name=reset action="{!check}">

Controller

    public boolean value{get;set};
public void check(){    
    if(picklist1 == 'yes')
    { 
    value=true;
    }
    else{
    value = false;
    }
}
1

Just because picklist2 is not rendered, it still retains its value. If you want it reset back to null each time the picklist1 value is changed, you need to do this yourself.

It looks as though you are already using an onChange function for your picklist1 value called reset(). You don't show that function here, but you need to reset the controller property value for picklist2 in that function. You can do this through an action function or through VF remoting.

EDIT

Just add a line to your check() method that resets the picklist2 value to blank.

public void check(){  
    picklist2 = '';  
    if(picklist1 == 'yes') { 
         value=true;
    }
    else{
         value = false;
    } 
}
  • "Reset()" is a action function(name), on change it goes to action function and calls check() method. <apex:actionfunction name=reset action="{!check}"> – cartman Jul 30 '14 at 2:10
  • Then I would alter check method to reset picklist1 value to null as well as setting the value property. – Chris Duncombe Jul 30 '14 at 2:13
  • ninja: I didn't understand, could you please edit the above code and show what exactly do I need to do. Thanks. – cartman Jul 30 '14 at 2:28
  • See edited answer above – Chris Duncombe Jul 30 '14 at 2:33
  • I'm afraid I cannot do that, as I have many other fields depending on other picklist1, picklist2 and other dependent field options. Is there any other way I could reset the field values? – cartman Jul 30 '14 at 2:38

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.