Programmatically Set Required Field

Forums Classic DFFS Programmatically Set Required Field

Viewing 3 reply threads
  • Author
    Posts
    • #17013
      sgjs2015
      Participant

      We have a (relatively) complicated setup where fields might become required or optional based on the value of other fields, so rather than keeping track of multiple rules, is it possible to set fields as required via JavaScript?

    • #17020
      Alexander Bautz
      Keymaster

      Hi,
      Required fields are stored in this array:

      spjs.dffs.data.requiredFields

      and you can push in new fields like this

      // Push new required field into array
      spjs.dffs.data.requiredFields.push("YourFieldName");
      // Show star on all required fields
      spjs.dffs.starRequired();

      If you need to remove a field from the array, you can use this function:

      spjs.dffs.data.requiredFields = spjs.dffs.removeFromArr(spjs.dffs.data.requiredFields,"YourFieldName");

      Alexander

    • #20955
      Keith Hudson
      Participant

      Alex;

      1. It looks like spjs.dffs.flag_Mandatory(‘FieldInternalName’) will set the field to required AND show the red star on that field. Is that correct?
      2. Is there an internal dffs function that does the opposite? (that is, sets the field to optional and removes the red star on that field? Or a function just to remove the red start, if we use spjs.dffs.data.requiredFields = spjs.dffs.removeFromArr(spjs.dffs.data.requiredFields,”YourFieldName”) to make the field optional again?

    • #20985
      Alexander Bautz
      Keymaster

      Sorry for the late reply – yes, you can use this snippet to do the opposite:

      spjs.dffs.clear_Mandatory(["Field1","Field2"]);

      Alexander

Viewing 3 reply threads
  • You must be logged in to reply to this topic.