Jump to content
  • 0

Set a Minimum Character for Form Element Text Area


Ruchitha

Question

3 answers to this question

Recommended Posts

  • 0

Hello @Ruchitha,

If this is the Submission form, you may test this code in the Footer section (disable the HTML editor before pasting the code):

<script>
document.addEventListener('BeforeFormSubmit', textAreaHandler);
document.addEventListener('DataPageReady', clearMessageHandler);

const textAreaField = document.querySelector('textarea[id*="InsertRecordField_name"]'); //replace Field_name with the needed field name

function textAreaHandler(event){
     const textAreaLength = textAreaField.value.length;
     if(textAreaLength < 10) {  // 10 is the minimum length, should be customized
         event.preventDefault();
         textAreaField.setCustomValidity('The value must contain 10 characters and more'); //customize the message
         textAreaField.reportValidity();
         return;
         }
     else{
         textAreaField.setCustomValidity('');
         }
}

function clearMessageHandler(){
     textAreaField.addEventListener('input', () => {
         textAreaField.setCustomValidity('');
     })
}
</script>

When the user clicks the 'Submit' button and the number of characters is less than needed this message will be displayed (for example):

fz3lVud.png

Hope this helps!

Link to comment
Share on other sites

  • 0

Hi Everyone!

Just wanted to add to @CoopperBackpack's great solution. 

In the following code:

const textAreaField = document.querySelector('textarea[id*="InsertRecordField_name"]'); //replace Field_name with the needed field name

The InsertRecordField_name can be changed to EditRecordField_Name if this is an update form.

This link may help.

Good luck!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...