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?

3
  • 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, 2019 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?
    – John John
    Mar 20, 2019 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.
    – John John
    Mar 23, 2019 at 0:18

1 Answer 1

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 and acknowledge that you have read and understand our privacy policy and code of conduct.

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