How to handle form load and form submit?

Forums Classic DFFS How to handle form load and form submit?

Viewing 1 reply thread
  • Author
    Posts
    • #33586
      Harsh
      Participant

      I have come across scenario where i need to bind some fields when new form will be open, value should be come from another list, i will use rest api call to get data from other list, but how can i bind data into field before form will be load?

      same, i will create some html input fields and want to store those field data into other SharePoint list on submit button, how can i achieve this?

      Thanks

    • #33590
      Alexander Bautz
      Keymaster

      When your REST call returns the value you want to fill in a field you use this function to set it:

      setFieldValue("The_field_internal_name_of_your_field", the_value_from_your_rest_call);

      Sending data to another list on save can be done by adding the HTML in a HTML section in your form, and then add this code to your Custom JS:

      // Keep track of the custom function being completed
      var hasSubmittedCustomHTML = false;
      // Used to ensure the custom HTML is not saved multiple times if save is not hit multiple times
      var isSavingCustomHTML = false;
      
      function doSaveCustomHTML(){
          // Add your custom REST call here and add the two below rows in the success/done callback from your REST call
          hasSubmittedCustomHTML = true;
          spjs.dffs.triggerSave();
      }
      
      function dffs_PreSaveAction() {
          if(!hasSubmittedCustomHTML){
              if(!isSavingCustomHTML){
                  isSavingCustomHTML = true;
                  // run your custom REST function to update another list
                  doSaveCustomHTML();
              }
              return false; // Return false to wait for the custom function to finish
          }else{
              // Custom HTML submitted - save item
              return true; // Continue saving item
          }
      }

      Please note that the actual HTML and the custom REST API call to save the custom HTML is not included here.

      Alexander

Viewing 1 reply thread
  • You must be logged in to reply to this topic.