Clearing the values of fiellds on form save

Forums Dynamic Forms for SharePoint Clearing the values of fiellds on form save

Viewing 3 reply threads
  • Author
    Posts
    • #28814
      AKOM
      Participant

      I have a complex multiple sections requirement where each section and fields under those are visible/hidden based on change of other dropdowns

      So I had to use custom JS.
      I have used rules just to trigger change of dropdowns
      onload I use this to hide all the fields and conditionally start showing them by doing this:
      $(spjs.dffs.fields[“Products”]).hide();

      Sometimes user might fill out a value or select dropdown value but then choose to select some other value which will hide this field.

      At the end on before save, I would like to clear any such values that were selected by user but are now hidden.
      $(“td[style$=’display: none;’]”).closest(‘tr’).find(“select”).each(function(i) {
      alert($(this).prop(‘title’));
      $(this).prop(‘selectedIndex’,’-1′);

      });
      This is clearing all selects not just the one with style$=’display: none;’
      Is there an easier way to clear all the fields that are not visible in a tab

    • #28832
      Alexander Bautz
      Keymaster

      I guess this is the same question as this one – so the answer is the same:

      var arrOfHidden = ["FieldOne", "FieldTwo"];
      jQuery.each(arrOfHidden, function(i, fin){
          setFieldValue(fin, "");
      });

      Alexander

    • #28841
      AKOM
      Participant

      Thank you. But I have some 70 fields that are conditionally shown and hidden.
      So I was trying to find some option to identify all those hidden elements at once, instead of building an array, on PreSaveAction
      The below code does the trick to reset the select dropdowns . But I was wondering if there is a better way or inbuilt option?

      
      
       function PreSaveAction()
      {    $("td[<strong>style$='display: none;</strong>']").closest('td').find("input").each(function(j) {
                $(this).attr('value','');
       });
       $("td[style$='display: none;']").closest('td').find("select").each(function(i) {
          $(this).prop('selectedIndex','-1');
         });
      }

      Is there an easy way to set fields to Not required when the fields are hidden in a dffs form? I am using flag_Mandatory and clear_Mandatory to conditionally make fields required and vice versa but it’s becoming very messy when I have multiple functions being called amking some fields to show and others to hide.

    • #28865
      Alexander Bautz
      Keymaster

      In general I would recommend that you used rules to control showing and hiding fields – is there a specific reason you use custom js and not rules?

      Alexander

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