You need to sign in to do that
Don't have an account?
sfdotcom
Visualforce page reRender
Hi,
I have created an object. Object Name: Text
Fieds:
1. Text Name(Standard field)
2. values (picklist field: values: 1, 2, 3)
3. Text 1 (Text field)
4. Text 2 (Text field)
5. Text 3 (Text field)
Now, I need a vf page. If I select picklist value as '1', then 'Text 1 ' field should be marked as required. If I select value '2', then 'Text 2 ' should be marked as required(red). Here we have to use reRender attribute and fields should be marked as required before saving.
<apex:page standardController="Text__c">
<apex:form>
<apex:pageBlock >
<apex:pageBlockSection id="thePageBlockSection">
<apex:inputField value="{!Text__c.Name}"/>
<apex:inputField value="{!Text__c.Text_values__c}" />
<apex:inputField value="{!Text__c.Text_1__c}" required="{!if(Text__c.Text_values__c== '1'), true, false}"/>
<apex:inputField value="{!Text__c.Text_2__c}" required="{!if(Text__c.Text_values__c== '2'), true, false}"/>
<apex:inputField value="{!Text__c.Text_3__c}" required="{!if(Text__c.Text_values__c== '3'), true, false}"/>
</apex:pageBlockSection>
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
Thank You.
I have created an object. Object Name: Text
Fieds:
1. Text Name(Standard field)
2. values (picklist field: values: 1, 2, 3)
3. Text 1 (Text field)
4. Text 2 (Text field)
5. Text 3 (Text field)
Now, I need a vf page. If I select picklist value as '1', then 'Text 1 ' field should be marked as required. If I select value '2', then 'Text 2 ' should be marked as required(red). Here we have to use reRender attribute and fields should be marked as required before saving.
<apex:page standardController="Text__c">
<apex:form>
<apex:pageBlock >
<apex:pageBlockSection id="thePageBlockSection">
<apex:inputField value="{!Text__c.Name}"/>
<apex:inputField value="{!Text__c.Text_values__c}" />
<apex:inputField value="{!Text__c.Text_1__c}" required="{!if(Text__c.Text_values__c== '1'), true, false}"/>
<apex:inputField value="{!Text__c.Text_2__c}" required="{!if(Text__c.Text_values__c== '2'), true, false}"/>
<apex:inputField value="{!Text__c.Text_3__c}" required="{!if(Text__c.Text_values__c== '3'), true, false}"/>
</apex:pageBlockSection>
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
Thank You.
Try below code for your requirement.
Visualforce Page:
Thank You,
Hitesh Patel
Email :- hiteshpatel.aspl@gmail.com
http://mrjavascript.blogspot.in/
All Answers
<apex:page standardController="Text__c">
<apex:form>
<apex:pageBlock >
<apex:pageBlockSection id="thePageBlockSection">
<apex:inputField value="{!Text__c.Name}"/>
<apex:actionRegion >
<apex:inputField value="{!Text__c.Text_values__c}" />
<apex:actionSupport event="onchange" reRender="1,2,3" />
</apex:inputField>
</apex:actionRegion>
<apex:inputField id ="1" value="{!Text__c.Text_1__c}" required="{!if(Text__c.Text_values__c== '1'), true, false}"/>
<apex:inputField id ="2" value="{!Text__c.Text_2__c}" required="{!if(Text__c.Text_values__c== '2'), true, false}"/>
<apex:inputField id ="3" value="{!Text__c.Text_3__c}" required="{!if(Text__c.Text_values__c== '3'), true, false}"/>
</apex:pageBlockSection>
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
Thanks u so much .
I am getting error as: "Error:1"
<apex:page standardController="Text__c">
<apex:form>
<apex:pageBlock >
<apex:pageBlockSection id="thePageBlockSection">
<apex:inputField value="{!Text__c.Name}"/>
<apex:actionRegion >
<apex:inputField value="{!Text__c.Text_values__c}" />
<apex:actionSupport event="onchange" reRender="as,bs,cs,ds" />
</apex:inputField>
</apex:actionRegion>
<apex:outputPanel id="ds">
<apex:inputField id ="as" value="{!Text__c.Text_1__c}" required="{!if(Text__c.Text_values__c== '1'), true, false}"/>
<apex:inputField id ="bs" value="{!Text__c.Text_2__c}" required="{!if(Text__c.Text_values__c== '2'), true, false}"/>
<apex:inputField id ="cs" value="{!Text__c.Text_3__c}" required="{!if(Text__c.Text_values__c== '3'), true, false}"/>
</apex:outputPanel >
</apex:pageBlockSection>
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
actually i tried below code and it's working fine as expected so check it if above is not working now .
<apex:page standardController="Contact">
<apex:form >
<apex:pageblock >
<apex:pageblockSection >
<apex:outputPanel layout="block" >
<apex:outputField value="{!Contact.Name}"/>
<apex:actionRegion >
<apex:inputField value="{!Contact.Padm__Demo_Picklist__c}" >
<apex:actionSupport event="onchange" reRender="as,bs,cs,ds" />
</apex:inputField>
</apex:actionRegion>
<apex:outputPanel id="ds">
<apex:inputField id ="as" value="{!Contact.Padm__Demo_text__c}" required="{!(Contact.Padm__Demo_Picklist__c== 'English')}"/>
<apex:inputField id ="bs" value="{!Contact.Padm__Demo_text__c}" required="{!(Contact.Padm__Demo_Picklist__c== 'hindi')}"/>
<apex:inputField id ="cs" value="{!Contact.Padm__Demo_text__c}" required="{!(Contact.Padm__Demo_Picklist__c== '3')}"/>
</apex:outputPanel >
</apex:outputPanel>
</apex:pageblockSection>
</apex:pageblock>
</apex:form>
</apex:page>
Try the below one, If alignment issue change it accordingly using pageblocksection or css style,
I got Syntax error. Extra ','
I am getting below error:
Error: text2 line 9, column 3: The element type "apex:actionregion" must be terminated by the matching end-tag "</apex:actionregion>" [Error] Error: The element type "apex:actionregion" must be terminated by the matching end-tag "</apex:actionregion>".
Try below code for your requirement.
Visualforce Page:
Thank You,
Hitesh Patel
Email :- hiteshpatel.aspl@gmail.com
http://mrjavascript.blogspot.in/
<apex:page standardController="Text__c">
<apex:form>
<apex:pageBlock >
<apex:pageBlockSection id="thePageBlockSection">
<apex:inputField value="{!Text__c.Name}"/>
<apex:actionRegion >
<apex:inputField value="{!Text__c.Text_values__c}" >
<apex:actionSupport event="onchange" reRender="as,bs,cs,ds" />
</apex:inputField>
</apex:actionRegion>
<apex:outputPanel id="ds">
<apex:inputField id ="as" value="{!Text__c.Text_1__c}" required="{!(Text__c.Text_values__c== '1')}"/>
<apex:inputField id ="bs" value="{!Text__c.Text_2__c}" required="{!(Text__c.Text_values__c== '2')}"/>
<apex:inputField id ="cs" value="{!Text__c.Text_3__c}" required="{!(Text__c.Text_values__c== '3')}"/>
</apex:outputPanel >
</apex:pageBlockSection>
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
I have created a record but i am not able to save it without giving "Text 1". "Text1" value becomes required even If i am not selecting any value in Text_Values__c.