I am working on a custom list inside sharepoint online classic UI. and inside the custom list i have 2 fields:-
- "ResponsibilityOwner" --> People/Group which allow single value.
- "ResponsibilityAssignedDate" --> Date only.
now i want to force the "ResponsibilityAssignedDate" to be required in-case the "ResponsibilityOwner" is not empty.
so inside the new/edit list forms i added this script, to check if the "ResponsibilityOwner" contain a user value:-
function PreSaveItem(){
var result = true;
var owner = $("input[id*='ResponsibilityOwner_']");
var attr = owner.attr('value');
alert(attr);
if (typeof attr !== typeof undefined && attr !== false || attr !== "[]") {
}
return result;
}
but i did not find any way that can allow me to check if the "ResponsibilityAssignedDate" contain a date value or not. as when i select a date from the calendar, i can not find how this is stored inside the related "ResponsibilityAssignedDate" input field?
so can anyone advice on this please?
PreSaveAction
as explained in the answer. In this function check forif ($('[id$="_$ClientPeoplePicker_HiddenInput"]').val() != '[]' && $('[id$="_$DateTimeFieldDate"]').val() === "") return false;
PreSaveAction
worked well for me,, i am not sure why my originalPreSaveItem
was not able to catch the date value?