Validate Multiple Line Text Field

Forums General discussion Validate Multiple Line Text Field

Viewing 5 reply threads
  • Author
    Posts
    • #28695
      Shawn Keene
      Participant

      My form has a multi-line “plain text” field. Our users are supposed to add comments anytime they are saving the form, but sometimes they just put a period so it will let them save it (it can’t be blank, but there’s no other validation).

      I was going to go set a simple column validation of =LEN([Comments])>5 so they had to at least type 5 characters, but apparently you can’t set validation on a multi-line text field.

      I hoped I could use a DFFS rule to accomplish this but couldn’t figure it out. I suspect I need to put it into the custom javascript section instead, but I’m not even sure how to begin to accomplish this.

    • #28701
      Alexander Bautz
      Keymaster

      You can add this to the dffs_PreSaveAction function in your Custom JS:

      function dffs_PreSaveAction(){
          var min = 10;
          var len = jQuery("#dffs_YOUR_FIELD_INTERNAL_NAME textarea").val().length;
          if(len < min){
              spjs.dffs.alert({
                  "title": "Please add more text in " + spjs.dffs.fieldData.YOUR_FIELD_INTERNAL_NAME.disp,
                  "msg": "You have typed in " + len + " characters, but need at least " + min + " characters to save this item."
              });
              return false;
          }
          return true;
      }

      Replace YOUR_FIELD_INTERNAL_NAME with your field’s internal name.

      Let me know how this works out.

      Alexander

    • #28703
      Shawn Keene
      Participant

      Thanks so much for your answer and awesome detailed example. Really appreciate it.

      PS. I have another pending post (probably because I attached a file), but I resolved it. Once it’s moderation-approved I’ll reply to it with the solution I used.

    • #28706
      Alexander Bautz
      Keymaster

      You’re welcome!

      I don’t see any pending comments – maybe it was flagged as spam and automatically removed by akismet (my spam protector).

      Alexander

    • #28710
      Shawn Keene
      Participant

      It would have been a separate topic, but basically I was wanting to combine the autocomplete search but also prefill the search with a URL key value (if present). I ended up adding this to my custom JS. It fills the value into the search box and triggers “keyup” so the search suggestions show. In practice for us there’s only ever going to be 1 search result.

      setTimeout(function(){
          var theValue = GetUrlKeyValue("ClientVal");
          if(theValue!=="") {
          document.getElementById("spjs_ac_Title").value = theValue;
          spjs.ac.hideHelp("Title");
          $("#spjs_ac_Title").keyup();
          }
      },2500);
      • This reply was modified 1 month, 2 weeks ago by Shawn Keene.
    • #28714
      Alexander Bautz
      Keymaster

      Thanks for sharing this tip!

      Alexander

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