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
sanshasansha 

Rerendering issue while making an input fields required attribute true

I need to show to the user if a field is mandatory or not. Hence I set the required attribute of the inputfield to true. However I see that on doing this the page rerendering does not take place unless one enters all the fields having required attribute as true.
 
Is there a work around ? I need to display the red mark before the field in order to indicate that the field is mandatory. Is it possible to achieve this without setting the required attribute of the input field to true ?
jeffdonthemicjeffdonthemic
This should do the trick for you.

http://blog.jeffdouglas.com/2008/11/16/displaying-the-required-red-bar-for-a-control/

Jeff Douglas
Informa Plc
blog.jeffdouglas.com
sanshasansha
I have a number of input fields of type lookup, multiselect , etc.
 
Do I need to put each of them in PageBlockSectionItem and segregate each of them as outputLabel and the component depending on the inputField type?  In this case I still see an issue with the Lookup field which references another object and multi-select field for which I am not aware of any corresponding component having the available and selected window as that of an input field of type multi-select.
 
Please suggest.
sanshasansha
It worked using the inputField as well.
<apex:pageblockSectionItem>
                      <apex:outputLabel value="FieldLabel" for="ip1"/>
                      <apex:outputPanel styleclass="requiredInput">
                      <apex:outputPanel styleClass="requiredBlock" layout="block"/>
                      <apex:inputField value="{!Table1__c.field1__c}" id="ip1"/>
                      </apex:outputPanel>
 </apex:pageblockSectionItem>
 
Thanks a Lot
jwetzlerjwetzler
I'm not understanding why you need to do this.

If your fields are already set as required in the custom field definition and you're inside of a pageBlock, they should appear as required automatically.  Likewise if you set them to required="true" inside of a pageBlock you should see the required bar and they will be validated on a post.  The only time you have to create the red bar yourself is if you are using inputText or you're outside of a pageBlock.  If you're just surrounding a field that's not required via the custom field definition with some CSS, it's never actually going to be validated for requiredness and your users will be able to save your page without entering all of the required fields.

If you are having problems with certain fields getting validated for requiredness during certain form posts, then search around the forums a bit because this question has been answered a lot.  You can either use the immediate="true" attribute on your action component or you can use actionRegion to specify only a certain region on the page that you want to be posted.
sanshasansha
I tried the below code
 
<apex:inputField value="{!Table1__c.field1__c}" required="true"/>
 
I get the red bar besides the field. However I see that the rendering that happens in other parts of the page(independant of the value in field1__c) stops unless I enter a value for field1__c.
 
By using the below code the rerendering that happens in other parts of the page works as expected.
 
<apexageblockSectionItem>
                      <apexutputLabel value="FieldLabel" for="ip1"/>
                      <apexutputPanel styleclass="requiredInput">
                      <apexutputPanel styleClass="requiredBlock" layout="block"/>
                      <apex:inputField value="{!Table1__c.field1__c}" id="ip1"/>
                      </apexutputPanel>
 </apexageblockSectionItem>
 
 
jwetzlerjwetzler
Please re-read my post.  Your solution is not a good idea because while the field appears required, the requiredness is not enforced.

The solution is either the immediate attribute on your action component, or the use of actionRegion to control your form post.  This has been discussed in several threads on these forums.
sanshasansha

I will have a look at the actionRegion to control form post.

In the meanwhile I want to know how to set the width of the field label. A single column in the the pageBlockSection spans two cells - one for the field's label and one for its value. I want to set the width differently for each of these cells.