Home › Forums › General discussion › Validate Multiple Line Text Field
Tagged: Javascript, validation
- This topic has 5 replies, 2 voices, and was last updated 4 years, 10 months ago by Alexander Bautz.
-
AuthorPosts
-
-
February 14, 2020 at 16:13 #28695
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.
-
February 14, 2020 at 21:38 #28701
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
-
February 14, 2020 at 21:40 #28703
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.
-
February 14, 2020 at 21:46 #28706
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
-
February 14, 2020 at 21:48 #28710
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 4 years, 10 months ago by Shawn Keene.
-
February 14, 2020 at 23:03 #28714
Thanks for sharing this tip!
Alexander
-
-
AuthorPosts
- You must be logged in to reply to this topic.