You need to sign in to do that
Don't have an account?

Validations for the check box in custom vfpage
Hi all,
I want to validate the custom check box before submitting Force.com sites custom vfpage. Can we use standard validation over here...? because i want to make the check box as mandetory. how can we achive this. Can anyone help me over here.
Thanks in advance.
regards,
Suneel.
I want to validate the custom check box before submitting Force.com sites custom vfpage. Can we use standard validation over here...? because i want to make the check box as mandetory. how can we achive this. Can anyone help me over here.
Thanks in advance.
regards,
Suneel.
Validations will apply even if you are saving via a visualforce controller.
If you want to display an input on a VF page as required (even though the field is not defined as required in the schema), you can do as follows:
I using the custom checkbox field in custom vfpage with custom controller. I have tried with div class which you have mentioned. but i still not able to validate the checkbox. can you help how we can validate the check box by using controller.
See here (http://salesforce.stackexchange.com/questions/22571/how-to-write-validation-in-visualforce/22635) for an example of writing validation in VisualForce page controller.
<apex:page showHeader="false" sidebar="false">
<apex:form >
<html>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$('[id$=btn]').click(function(){
if($('#chk2').prop('checked') == false){
alert('Please select the checkbox');
return false;
}
});
});
</script>
Do u need ? <input type="checkbox" id="chk2"/><br/>
<apex:commandButton onclick="fn()" id="btn" value="Save"/>
</html>
</apex:form>
</apex:page>
Thanks.
I have tried this but value is saving as false when the record is saved.
If you are using custom controller .
Hope it will work for you.
Page:
-------------------
<apex:page showHeader="false" sidebar="false" controller="savecontroller">
<apex:form >
<html>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$('[id$=btn]').click(function(){
if($('#chk2').prop('checked') == false){
alert('Please select the checkbox');
return false;
}
else{
Callingcontrollermetod();
}
});
});
</script>
<apex:actionFunction name="Callingcontrollermetod" action="{!savemethod}" reRender=""/>
Do u need ? <input type="checkbox" id="chk2"/><br/>
<apex:commandButton onclick="fn()" id="btn" value="Save"/>
</html>
</apex:form>
</apex:page>
Controller :
---------------------
public with sharing class savecontroller {
Public void savemethod(){
system.debug('I am called');
}
}
Thanks.