trigger function on spjs.casc.add

Forums Cascading dropdowns trigger function on spjs.casc.add

Viewing 5 reply threads
  • Author
    Posts
    • #29687
      Jon Whisman
      Participant

      Hi,

      I’m using the cascading dropdowns multi item functionality and I want to trigger a custom function when items are added.

      I see spjs.casc.add(“internalFieldName,internalFieldName,0) in the console for the add button. How to use this to trigger my function on each add or remove?

    • #29720
      Alexander Bautz
      Keymaster

      I haven’t built in any “hooks” you can use, but by just adding something like this to your custom js you can pick up all changes:

      jQuery("#dffs_LOB").find('input:text,textarea').on("change", function(){
          console.log(jQuery(this).val());
      });

      In this example the field internal name is LOB so you must replace that with your field internal name.

      Alexander

    • #29740
      Jon Whisman
      Participant

      Thank you very much, Alexander! This worked for text field, but not the “select” drop down options for other fields.

      Would you happen to know how I can trigger a change event for sharepoint dropdown columns? I tried the below, but it does not work.

      jQuery(“dffs_FIELDNAMEHERE”).find(‘input”select’).on(“change”, function(){
      //my code
      });

    • #29747
      Alexander Bautz
      Keymaster

      You must use this format to get the value of a normal dropdown (the value in the casc-dropdown is stored in a text field or textarea hidden behind the controls):

      jQuery("#dffs_YOUR_FIELD_NAME").find("select").on("change", function(){
          var opt = jQuery(this).find("option:selected");
          var id = opt.val();
          var txt = opt.text();
          console.log(id+":"+txt);
      });

      Alexander

    • #29756
      Jon Whisman
      Participant

      Thank you, Alexander.

      I’m using jQuery UI with DFFS. Any way to detect an on change event for a date field? My code will run when I type a date, but not when I use the jqueryUI date selector widget.

      jQuery(“#dffs_Date1”).find(“input”).datepicker();

    • #29758
      Alexander Bautz
      Keymaster

      You can use something like this:

      var currentDateFieldValue = getFieldValue("Date1");
      setInterval(function(){
          var val = getFieldValue("Date1");
          if(val !== currentDateFieldValue){
              currentDateFieldValue = val;
              // trigger your code here
          }
      },500);

      Alexander

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