Show Character Limit of Input

If a user is inputting text such as Short Text or Paragraph Text, you might want to validate against putting large amounts of text if this input is going to be printed. While Knack does provide a validation rule against character length, the user might not necessarily knows how many characters they can input in a field until submission.

Below is the expected behavior of the custom code.

The JS

Add the following code below. The only code you will have to modify in your app is line 39. The function parameters asks for:

  • The view ID in Knack.

  • The field ID which is what input you want the character limit to show below.

  • The charLimit which you can set the character limit for the text input.

Option A - only a couple fields

If it is only a couple of fields modify line 39 above. Change the view_XXX, field_XXX and 500 to what you want it set to.

Option B - many fields

If you have many fields, you might want to store the field IDs as a list and use a for loop. You would then need to replace line 39 with the code snippet below.

The CSS

None needed.

Note

  • If you use Option B, it will set the character limit to the same number. If needed, you can get around this by using Option A, or by storing the field IDs and the character limit value as a dictionary instead of an array.

Last updated

Was this helpful?