0

I am working on a custom list inside sharepoint online classic UI. and inside the custom list i have 2 fields:-

  1. "ResponsibilityOwner" --> People/Group which allow single value.
  2. "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?

here are the 2 fields:- enter image description here

so can anyone advice on this please?

  • 1
    Better use PreSaveAction as explained in the answer. In this function check for if ($('[id$="_$ClientPeoplePicker_HiddenInput"]').val() != '[]' && $('[id$="_$DateTimeFieldDate"]').val() === "") return false; – Steve T Mar 20 at 19:17
  • @SteveT you approach of using PreSaveAction worked well for me,, i am not sure why my original PreSaveItem was not able to catch the date value? – SharePoint TestDev Mar 20 at 21:27
  • @Steve T your above code worked for me,, if u can add your comment as a reply so i can accept it.. thanks for the help. – SharePoint TestDev Mar 23 at 0:18
0

Better use PreSaveAction . In this function check for:

if ($('[id$="_$ClientPeoplePicker_HiddenInput"]').val() != '[]' &&  $('[id$="_$DateTimeFieldDate"]').val() === "") { return false; }

(depending on the number of peolplepickers and date fields in your form you might have to adjust the selectors)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.