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
d.tejdeep@nicomatic.ind.tejdeep@nicomatic.in 

Making field required based on user input on other input field ?

<td><apex:inputField value="{!child.batchObj.Asked_Qty__c}"/></td>
                                                   
<td><apex:inputfield value="{!child.batchObj.Quantity__c}"  required="{!child.batchObj.Asked_Qty__c=0}" style="width:110px"/></td>


When inputfield  "Asked_Qty__c" was empty .then "Quantity__c" was not required .

When inputfield  "Asked_Qty__c" was not empty .then "Quantity__c" was  required 

I want to do this asked quantity was entered by salesforce user ?

Based on input it should take required or not require  ?

How can i do this Thanks in Advance ?
 

N.V.V.L.Vinay KumarN.V.V.L.Vinay Kumar
Hi TejDeep,

Try this
<td>
<apex:inputField value="{!child.batchObj.Asked_Qty__c}">
    <apex:actionSupport event="onChange" rerender="blck"/>
</apex:inputField>
</td>
<td><apex:inputfield value="{!child.batchObj.Quantity__c}" required="{!IF(child.batchObj.Asked_Qty__c!=null,TRUE,FALSE)}" style="width:110px"/></td>

If you are using page block in the page then peovide id for that pageblock as blck, and remeber form tag should be used.

Reagrds,
N. Vinay Kumar.
d.tejdeep@nicomatic.ind.tejdeep@nicomatic.in
Hi 

Thanks for your answer

This is not working i tried before also the same 

 
Amit Chaudhary 8Amit Chaudhary 8
Try below code:-
<td>
<apex:inputField value="{!child.batchObj.Asked_Qty__c}">
    <apex:actionSupport event="onChange"  action="{!ShowField}"/>
</apex:inputField>
</td>
<td><apex:inputfield value="{!child.batchObj.Quantity__c}" required="{!isRequired}" style="width:110px"/></td>
Class
public boolean isRequired {get;set;}

pageReference ShowField()
{
  if(child.batchObj.Asked_Qty__c != null)
 {
 isRequired = true
 }
else
{
 isRequired = false;
}
}


Please let us know if this will help you

Thanks
Amit Chaudhary
KaranrajKaranraj
While rerendering you have to mention the id of the section 
Check the below sample code
<apex:page Controller="simpleController" >
<apex:form >
    <apex:pageBlock title="Test">
        <apex:actionRegion >
        <apex:pageBlockSection columns="1">
            <apex:inputField value="{!child.batchObj.Asked_Qty__c}">
                <apex:actionSupport event="onchange" action="checkboolean" rerender="theSection"/>
            </apex:inputField>
        </apex:pageBlockSection>
        </apex:actionRegion>
        <apex:pageBlockSection columns="1" id="theSection">
      <apex:inputField value="{!child.batchObj.Quantity__c}" required="{!requireAddress}"/>
        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:form>
</apex:page>

Sample Apex controller
public with sharing class simpleController
{
   
    public Boolean requireAddress { get { return child.batchObj.Asked_Qty__c!=null ? True : False; } }

}


 
RatanRatan
<apex:page showHeader="true" sidebar="true" controller="RN_AngularMaterialDesign" docType="html-5.0" >
	<apex:form id="frm">
	    <apex:inputField value="{!objAcc.SLASerialNumber__c}" onkeyUp="makeRequired(this);" id="input"/>
	    <apex:inputField value="{!objAcc.AccountNumber}" id="input1"/>
	    <button type="submit">Submit</button>
	
	<script>
	    function makeRequired(inputVal)
	    {
	        if(inputVal.value != '')
	            document.getElementById('{!$Component.input1}').required = 'required';
	    }
	</script>
	</apex:form>
</apex:page>

Bro try with above code and let me know if it is working or not.


If this solve you problem mark this as best answer to help others.