function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
vanessenvanessen 

Rerendering not working when field is required

I noticed that , rerenderinf do not work, when the field is required , anyone know why is it the case ?

 

<apex:outputPanel id="header01"  layout="block" styleClass="pbHeader">            
                 <table class="detailList" cellspacing="0" cellpadding="0" border="0">                           
                    <tr>
                       <td class="labelCol">{!$ObjectType.DomaineMarque__c.fields.Name.label}</td>
                        <td class="dataCol" style="width:70%">
                             <div class="requiredInput">
                                <div class="requiredBlock"></div>
                                 <apex:selectList id="dom" value="{!selectedDomaine}" size="1" onchange="RefreshHeader();">
                                      <apex:selectOptions value="{!DomaineList}"/>
                                 </apex:selectList>
                                 <apex:actionFunction name="RefreshHeader" immediate="true" action="{!Refresh}" rerender="header01" status="myStatus" />
                              </div>
                          </td>
                    </tr>
                    <tr style="display:{!IF(selectedDomaine == 'new','','none')}">
                        <td class="labelCol">{!$ObjectType.DomaineMarque__c.fields.Type__c.label}</td>
                        <td class="dataCol"><apex:inputfield value="{!domaine.Type__c}" /></td>
                    </tr>
                    <tr style="display:{!IF(selectedDomaine == 'new','','none')}">
                        <td class="labelCol">{!$ObjectType.DomaineMarque__c.fields.Article__c.label}</td>
                        <td class="dataCol"><apex:inputfield value="{!domaine.Article__c}"/></td>
                    </tr>
                    <tr style="display:{!IF(selectedDomaine == 'new','','none')}">
                        <td class="labelCol">{!$ObjectType.DomaineMarque__c.fields.Nom__c.label}</td>
                        <td class="dataCol"><apex:inputfield value="{!domaine.Nom__c}" required="true"/></td>
                    </tr>  
                </table>          
           </apex:outputPanel>

 

if i remove the required=true part, the rerendering works fine. Is this a salesforce bug?

Gunners_23Gunners_23

Yes i have came accross this issue. I'm not sure whether its a bug or not. Even in my case it was working when i remove

 

Required=true or "When i enter the value for that field" and then do the ajax call ( in this case selectList)

Pravesh RanaPravesh Rana

Hi,

 

No what happen is that "Is required" condition did not let the page call controller, as it first check the required fields if they contain null values, it cancels the call to Controller and shows error.

And a section is rerendered only if the controller is called. 
 

vanessenvanessen

I agree, but according to my code, the field isvisible only when the rerendering occur. So you think that , even if the style is set to not visible, the field is here in the dom , and is required by some validation ? I set my actionfunction to immediate=true, to bypass any validation beforehand, but didn't solve my problem

bob_buzzardbob_buzzard

I always add an apex:pageMessages to the page and include the id for this on the rerender attribute.  Otherwise, any error that occurs (including validation rules and trigger failures) gets swallowed and the user has no idea why the form won't submit.

Pravesh RanaPravesh Rana

Yes, visiblity  != Rendered(false)

 

only Rendered(false) can ignore the "is required" condition

 

you can always apply " * " method 

 

say in the start of page that field with ' * ' are compulsary , than apply validation in the controller and show error message if values are missing. 

vanessenvanessen

But then why, setting my immediate=true not working, why is it validating ?
if not working i am going to the solution, where i will validate via javascript itself or in the controller.

Thanks for the discussion guys.

Pravesh RanaPravesh Rana

Because "Immediate" is there to over rule any other processes that are going on at that event  and call Controller and "IS required" is going to run before the controller is called, so Immediate is not going to overrule  "IS required".

 

Best way will be to do the validation in Contoller. You have more freedom and less chaces of error.

bob_buzzardbob_buzzard

All immediate means is that any changes made by the user are discarded.  The validation that is done client side (on required) won't be affected by that.

Soni21Soni21

<apex:actionRegion immediate="true">
<apex:pageBlockSection columns="2" title="Information" id="jobtrackerDetailPbs">


<apex:pageBlockSectionItem>
<apex:outputLabel value="Process Name"> </apex:outputLabel>
<apex:outputPanel styleClass="requiredInput" layout="block">
<apex:outputPanel styleClass="requiredBlock" layout="block"/>
<apex:inputfield id="ProcessName" value="{!Process_Name__c}" label="Process Name" />
</apex:outputPanel>
</apex:pageBlockSectionItem>

<apex:pageBlockSectionItem>
<apex:outputLabel value="Location"> </apex:outputLabel>
<apex:outputPanel styleClass="requiredInput" layout="block">
<apex:outputPanel styleClass="requiredBlock" layout="block"/>
<apex:inputfield id="Location1" value="{!Location__c}" />
</apex:outputPanel>
</apex:pageBlockSectionItem>

 

</apex:pageBlockSection

</apex:actionRegion>

vanessenvanessen
To avoid all these issues, now when i work with visualforce page which such requirement, I use jquery to validate the field on the client side , without using the required=true.