It is possible to check validation of list fields before the save button is clicked on a list form:
Suppose, We have a list form like below:
If the Save button is pressed, a method named PreSaveAction() is always executed by default. You can just write a function named as PreSaveAction in a .js file and link the file to the desired list form.
You can place all your validation code in the method as shown in the section below. These validations are client side validation using jquery.
function PreSaveAction()
{
//--List Field HRBP
if($('#ctl00_SPWebPartManager1_g_840570ae_f359_466e_b37c_b99ae98c9690_ff21_ctl00_ctl00_UserField').text().trim() =="")
{
$('#vld-hrbp').show();
$('#vld-hrbp').css('color','red');
return false;
}
else
{
$('#vld-hrbp').hide();
}
//---List Field Hiring Manager
if($('#ctl00_SPWebPartManager1_g_840570ae_f359_466e_b37c_b99ae98c9690_ff31_ctl00_ctl00_UserField').text().trim() == "")
{
$('#vld-hrmanager').show();
$('#vld-hrmanager').css('color','red');
return false;
}
else
{
$('#vld-hrmanager').hide();
$('#vld-hiring-depatment').hide()
}
}
Happy SharePointing........................:)
No comments:
Post a Comment