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
anup-prakashanup-prakash 

Making field required

Hi I have a vfPage and it has three command buttons to rerender the three output panels containing textboxes.. and I want to make these textboxes required on the basis of the output panel being selected via the command button selection..

Action region not helping

sekharasekhara

Keep Required = True

anup-prakashanup-prakash
that doesn't help as it doesn't allow me to rerender the other output panels once one is selected..
Avidev9Avidev9
well the event that is hiding the components say command button or actionfunction or action support.

add immediate = true.

anup-prakashanup-prakash
Hi Avi you are a God sent.. In the salesforce guide they haven't explained quite well.. could you please tell me what does this immediate attribute do?
anup-prakashanup-prakash
<apex:page controller="ProductController">
    <apex:form >
        <apex:pageBlock title="Products" >
            <apex:pageBlockSection id="pbs1" columns="3">
                <apex:commandButton action="{!searchProductDisplay}" reRender="pbs2,pbs3,pbs4" value="Search Product" />
                <apex:commandButton action="{!newProductDisplay}" reRender="pbs2,pbs3,pbs4" value="New Product" />
                <apex:commandButton action="{!addLotDisplay}" reRender="pbs2,pbs3,pbs4" value="Add Lot" />
            </apex:pageBlockSection>
            <apex:outputPanel id="pbs2" >
            <apex:pageblockSection title="Search Product" rendered="{!searchSection}">
                <apex:pageBlockSectionItem >
                
                </apex:pageBlockSectionItem>
            </apex:pageblockSection>
            </apex:outputPanel>
            <apex:outputPanel id="pbs3">
            <apex:pageblockSection title="Add New Product" rendered="{!addNewSection}">
                <apex:pageBlockSectionItem >
                    <apex:outputText value="Product Name" />
                    <apex:inputText value="{!productName}" title="Enter the Product Name" required="true" />
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    <apex:outputText value="Desctiption" />
                    <apex:inputText value="{!description}" title="Enter the Product Description"/>                    
                </apex:pageblocksectionItem>
                <apex:pageBlockSectionItem >
                    <apex:outputText value="Manufacturer" />
                    <apex:inputText value="{!manufacturer}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    <apex:outputText value="MRP"/>
                    <apex:inputText value="{!mRP}" />
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    <apex:outputText value="Unit Price"/>
                    <apex:inputText value="{!unitPrice}" />
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    <apex:outputText value="Batch Number"/>
                    <apex:inputText value="{!batchNumber}" />
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    <apex:outputText value="Quantity"/>
                    <apex:inputText value="{!quantity}" />
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    <apex:commandButton action="{!saveNew}" value="save" title="Save"/>
                </apex:pageBlockSectionItem>                                                
            </apex:pageblockSection>
            </apex:outputPanel>
            <apex:outputPanel id="pbs4">
            <apex:pageblockSection title="Add Lot to Product" rendered="{!addLotSection}">
                <apex:pageBlockSectionItem >
                    <apex:outputText value="Product"/>
                    <apex:selectList value="{!productID}" multiselect="false" size="1">
                        <apex:selectOptions value="{!productList}" >
                        </apex:selectOptions>
                    </apex:selectList>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    <apex:outputText value="MRP"/>
                    <apex:inputText value="{!mRP}" />
                </apex:pageBlockSectionItem>                
                <apex:pageBlockSectionItem >
                    <apex:outputText value="Unit Price"/>
                    <apex:inputText value="{!unitPrice}" />
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    <apex:outputText value="Batch Number"/>
                    <apex:inputText value="{!batchNumber}" />
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    <apex:outputText value="Quantity"/>
                    <apex:inputText value="{!quantity}" />
                </apex:pageBlockSectionItem>
                <apex:pageblocksectionItem >
                    <apex:commandbutton action="{!addLot}" value="Add Lot" title="Add Lot to existing Product" />
                </apex:pageblocksectionItem>
            </apex:pageblockSection>
            </apex:outputPanel>                        
        </apex:pageBlock>
    </apex:form>
</apex:page>

 In this piece of code could you please tell as to iff I have to use it in the top three or the command buttons inside the panels?

Avidev9Avidev9

LOL...... Nothing like that I just read the document carefully ;)

Here is a description about the immediate attribute :

A Boolean value that specifies whether the action associated with this component should happen immediately, without processing any validation rules associated with the fields on the page. If set to true, the action happens immediately and validation rules are skipped. If not specified, this value defaults to false.

 

This means basically it will skip any page validation and additionally no setter will be called. So You should mark all the commandbutton, which doesnt depend on page data to process something as immediate = true

AdrianCCAdrianCC

Hello,

 

Just my 2cents, but required + immediate is quite a headache, it's not too well documented and sometimes it doesn't work as intended(I had a similar problem, see my posts).

 

I would remove required from the page(also immediate) and move the validations to the commandbuttons actions - serverside. In case your needed field doesn't have a value throw a message to the user using pagemessages or addError, or build a custom error String etc

 

Thanks,

Adrian