Adding jQuery Script to DFFS

Forums Classic DFFS Adding jQuery Script to DFFS

Viewing 1 reply thread
  • Author
    Posts
    • #11765
      Ken Morley
      Participant

      Hi,

      I have tried adding your sample script to the Custom JS tab section but it returns an error ‘You cannot use script tags in the custom JS’.

      The code I am trying to add is from your previous post as I wanted to see how it works, so from this you will see I don’t have much experience with jQuery, but I wanted to learn how to utilize it with the forms.

      Thanks,

      Ken

      The script I posted in the Custom JS section.

      [javascript]
      <script type=”text/javascript” src=”/Javascript/jquery-2.2.4.min.js”></script>
      <script type=”text/javascript”>
      fields = init_fields();

      var myNewLabel = “<br><div>Here is some custom text added by adressing the formlabel with jQuery!</
      [javascript]
      <script type=”text/javascript” src=”/Javascript/jquery-2.2.4.min.js”></script>
      <script type=”text/javascript”>
      fields = init_fields();

      var myNewLabel = “<br><div>Here is some custom text added by adressing the formlabel with jQuery!</div>” +
      “<br><div>You can insert images to:<br></div>”

      $(fields[‘MyChoice’]).find(“.ms-formlabel h3”).after(myNewLabel);

      // Array of all descriptions – must be the same number of elements as the number of choices in the choice-list
      var arrMyChoice = [‘Description for choice 1’,
      ‘Description for choice 2’,
      ‘Description for choice 3’,
      ‘Description for choice 4’,
      ‘Description for choice 5’,
      ‘Description for choice 6’,
      ‘Description for choice 7’,
      ‘Description for choice 8’,
      ‘This is the longest: Description for choice 9’,
      ‘Description for choice 10’,
      ‘Description for choice 11’,
      ‘Description for choice 12’,
      ‘Description for choice 13’,
      ‘Description for choice 14’,
      ‘Description for choice 15’,
      ‘Description for choice 16’,
      ‘Description for choice 17’,
      ‘Description for choice 18’,
      ‘Description for choice 19’,
      ‘Description for choice 20’];

      // Call the script that inserts the descriptions
      descriptionBeforeChoice(‘MyChoice’,arrMyChoice,300);

      function descriptionBeforeChoice(FieldInternalName,arrName,widthOfCustomLabel){
      $(fields[FieldInternalName]).find(“.ms-formbody”).find(“:checkbox”).each(function(idx){
      // Add alternating style to make it easier to follow the lines in the form
      var trClass = ”;
      if(idx%2==0){
      trClass = ‘ms-alternatingstrong’;
      }
      $(this).before(“<span style=’display:inline-block;width:” + widthOfCustomLabel + “;white-space:nowrap’>” + arrName[idx] + “</span>”)
      .parent().css({‘white-space’:’nowrap’})
      .parents(‘tr:first’).addClass(trClass);
      });
      }

      function init_fields(){
      var res = {};
      $(“td.ms-formbody”).each(function(){
      if($(this).html().indexOf(‘FieldInternalName=”’)<0) return;
      var start = $(this).html().indexOf(‘FieldInternalName=”’)+19;
      var stopp = $(this).html().indexOf(‘FieldType=”’)-7;
      var nm = $(this).html().substring(start,stopp);
      res[nm] = this.parentNode;
      });
      return res;
      }
      </script>
      [/javascript]

    • #11803
      Alexander Bautz
      Keymaster

      Hi,
      Sorry for the delay. You cannot use the <script> tag in the Custom JS. Just skip them and you code should run.

      When you cannot include script tags this means you must use only “inline” JS and cannot refer any external library directly. If you need to use another external script you can use $.getScript() – https://api.jquery.com/jquery.getscript/

      Alexander

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