We have a Travel Reason Choice/Checkboxes (allow multiple selections) column with values:
- Conference
- Customer Visit
- Site Visit
- Summit
- Training
We also have date fields for each of these travel reasons.
The default validation option for the list won't pick up this column type.
How can we validate for any of the checked items + verify if the appropriate date is filled in?
So, if they check Conference, Site Visit and Training (since a travel session could cover all 3), we need to verify they have the dates populated (other columns) for these 3 travel types.
********Update: choice field + date validation solved with code below, but now default SharePoint validation doesn't outline required fields.
<script type="text/javascript">
function PreSaveAction() {
var myCheckbox = $('#Travel_x0020_Type_a16cb653-3c2e-4065-b2ba-eace5d2ef1cd_MultiChoiceOption_0');
var chkTraining = $('#Travel_x0020_Type_a16cb653-3c2e-4065-b2ba-eace5d2ef1cd_MultiChoiceOption_4');
var checkedConf = $(myCheckbox).is(":checked"); //is Conference checkbox checked (true/false)?
var checkedTraining = $(chkTraining).is(":checked"); //is Training checkbox checked (true/false)?
var calConfStartDateEmpty= $('#Conference_x0020_Travel_x0020_De_74ff820f-5e96-4d0c-a5f3-bc704b401af8_\\$DateTimeFieldDate').val().length === 0;
var calConfEndDateEmpty = $('#Conference_x0020_End_x0020_Date__69dfc50f-5a3f-4a2f-96ef-d7b2c4ba8757_\\$DateTimeFieldDate').val().length === 0;
var calTrainingStartDateEmpty= $('#Training_x0020_Start_x0020_Date__ff2bd66a-57cc-47f5-b27f-43d7d14ab089_\\$DateTimeFieldDate').val().length === 0;
var calTrainingEndDateEmpty = $('#Training_x0020_End_x0020_Date_x0_cfa76e5e-3cb4-49d2-8918-e96dfb7379f3_\\$DateTimeFieldDate').val().length === 0;
if (checkedConf == true)
{if (calConfStartDateEmpty == true || calConfEndDateEmpty == true)
alert("If Conference Travel Reason is selected, please make sure both Conference Dates are populated");}
if (checkedTraining == true)
{if (calTrainingStartDateEmpty == true || calTrainingEndDateEmpty == true)
alert("If Training Travel Reason is selected, please make sure both Training Dates are populated");}
}
</script>