You need to sign in to do that
Don't have an account?
Jyotirupa Das
Remove the validation message of required field on check of the checkbox field
I want to remove the salesforce validation rule on check of checkbox in VF page. It is workig for first time but if we try to submit the page without filling any of the required field, the field validation is showing up again.
This is the script
<script type="text/javascript">
$(document).ready(function(){
$("[id$=enabledisablecheckbox]").change(function(){
if(this.checked==true){
$("[id$=FirstName]").prop("disabled",true);
$("[id$=LastName]").prop("disabled",true);
$("[id$=LastName]").prop("value",null);
$("[id$=FirstName]").prop("value",null);
if($(".anonymousFN")[0].parentElement != null){
$(".anonymousFN")[0].parentElement.children[0].className = '';
$(".anonymousLN")[0].parentElement.children[0].className = '';
//$(".anonymousFN")[0].value = 0;
}
//$("[id$=FirstName]").prop("required",false);
// $("[id$=LastName]").prop("required",false);
// $("[id$=FirstName]").required = false;
}
else{
$("[id$=FirstName]").prop("disabled",false);
$("[id$=LastName]").prop("disabled",false);
// $("[id$=FirstName]").prop("required",true);
// $("[id$=LastName]").prop("required",true);
if($(".anonymousFN")[0].parentElement != null){
$(".anonymousFN")[0].parentElement.children[0].className = 'requiredBlock';
$(".anonymousLN")[0].parentElement.children[0].className = 'requiredBlock';
}
}
});
});
</script>
here is the defination
<apex:pageblockSectionItem >
<apex:outputLabel value="{!$Label.GMI_Anonymous_Contact}" ></apex:outputLabel>
<apex:inputCheckbox value="{!cas.AnonymousContact__c}" id="enabledisablecheckbox" onClick="disableEnableField()" />
</apex:pageblockSectionItem >
Can someone please help!!
This is the script
<script type="text/javascript">
$(document).ready(function(){
$("[id$=enabledisablecheckbox]").change(function(){
if(this.checked==true){
$("[id$=FirstName]").prop("disabled",true);
$("[id$=LastName]").prop("disabled",true);
$("[id$=LastName]").prop("value",null);
$("[id$=FirstName]").prop("value",null);
if($(".anonymousFN")[0].parentElement != null){
$(".anonymousFN")[0].parentElement.children[0].className = '';
$(".anonymousLN")[0].parentElement.children[0].className = '';
//$(".anonymousFN")[0].value = 0;
}
//$("[id$=FirstName]").prop("required",false);
// $("[id$=LastName]").prop("required",false);
// $("[id$=FirstName]").required = false;
}
else{
$("[id$=FirstName]").prop("disabled",false);
$("[id$=LastName]").prop("disabled",false);
// $("[id$=FirstName]").prop("required",true);
// $("[id$=LastName]").prop("required",true);
if($(".anonymousFN")[0].parentElement != null){
$(".anonymousFN")[0].parentElement.children[0].className = 'requiredBlock';
$(".anonymousLN")[0].parentElement.children[0].className = 'requiredBlock';
}
}
});
});
</script>
here is the defination
<apex:pageblockSectionItem >
<apex:outputLabel value="{!$Label.GMI_Anonymous_Contact}" ></apex:outputLabel>
<apex:inputCheckbox value="{!cas.AnonymousContact__c}" id="enabledisablecheckbox" onClick="disableEnableField()" />
</apex:pageblockSectionItem >
Can someone please help!!
You can try "Rendered" attribute on fields. Do not render those fields in page when checkbox is checked true(Instead of using "Disabled" attribute).
Thanks
Could you please provide me example how to do it.
Thanks
Your ask seems similar to this
https://salesforce.stackexchange.com/questions/122056/how-to-remove-required-field-validation-in-a-visualforce-page
https://salesforce.stackexchange.com/questions/121496/required-field-off-when-unchecked?rq=1
Try this approach :
To make inputfields required by checkbox value, provide attribute required="{!checkboxField}" for you fields. Add AJAX support within actionSupport to your checkbox, where you could rerender required fields.
Given page utilizes opportunity standardcontroller, where you already have checkbox field:
actionRegion will send only checkbox field to server during validation. Save will send whole form.
If this information helps, please mark the answer as best. Thank you