Skip to main content
sarathkumr268295
May 8, 2024
Question

Restricting user from entering text after certain character limit

  • May 8, 2024
  • 9 replies
  • 0 views

Hi all,
We have a business requirement where the user will enter data into a text field and if the data reaches a certain character limit say 100, we should not allow users to type more than 100. Like they want it to be freezed or stopped at 100 character length? We are showing character limit validation but they want some kind of restriction. Is it possible to achieve to such feature?

9 replies

stefanhelzle0001
Brainy
May 8, 2024

No, you cannot prevent the user from continue typing.

In case this is a deal breaking requirement, which I have my doubts on, this would call for a custom component plugin.

sarathkumr268295
May 8, 2024

 [mention:a11f77a729fb4db2af76b09948583328:e9ed411860ed4f2ba0265705b8793d05] ,custom component plugin means something we should build or are they already available in app market?
Plus, its not like a deal breaking requirement, just they are expecting something more out of appian

stefanhelzle0001
Brainy
May 8, 2024

I do not suggest to go that route, but to push back that "requirement".

And yes, you would have to build that yourself.

Everybody has its own set of expectations, but Appian cannot make everybody happy ;-)

harshk1671
May 8, 2024

You can try using the below code:

a!localVariables(
  local!description,
  a!textField(
    label: "Description",
    instructions: "You can only add 100 characters in this field, system will auto trim the characters after 100th character",
    value: local!description,
    saveInto: {
      a!save(local!description, left(save!value, 100))
    }
  )
)

This way it will never throw the validation but auto trim the characters after 100.

sarathkumr268295
May 8, 2024

[mention:8e5a7a058e4f4768ba94c8d9526dd3e4:e9ed411860ed4f2ba0265705b8793d05] , we tried the same but you can enter the data after 100 also. Unless there is a key press, it will continue to allow and only when a key is pressed, the save will execute and that is something which business wont accept.

harshk1671
May 8, 2024

This is a really specific case [emoticon:c4563cd7d5574777a71c318021cbbcc8]

You can discuss with business why they want it specifically and then push back explaining the behaviour of Appian components.

mikes0011
Brainy
May 8, 2024

I have found it LARGELY sufficient to simply utilize Appian's newer, built-in "character limit" functionality with "show character limit" turned ON.

It does not physically STOP users from entering more characters than the limit, but it is VERY visible and makes it VERY easy for the user to comply.

If you MUST have something like you describe (which i'd be curious to hear the business owners' rationale behind), then a solution like HARSH posted above but with "refresh after keypress" turned on, will be your closest option.  It won't work perfectly though.  (You can use the character limit visibility to your advantage here too).

Edit: actually "refresh on keypress" doesn't help a whole lot here - either way, here's my revised code (shortened the limit temporarily for easier testing)

a!localVariables(
  local!description,
  local!limit: 20,
  
  a!textField(
    label: "Description",
    instructions: "You can only add " & local!limit & " characters in this field, system will auto trim the characters after 100th character",
    value: local!description,
    refreshAfter: "KEYPRESS",
    characterLimit: local!limit,
    showCharacterCount: true(),
    saveInto: {
      a!save(local!description, left(save!value, local!limit))
    }
  )
)

sarathkumr268295
May 8, 2024

We did the same [mention:b45a4f6a20b14a008e4e0ec732a8bf98:e9ed411860ed4f2ba0265705b8793d05] . This is the closest we can go but it does not seem that much convincing to the business. They are expecting like a hardstop which they are comparing it with some other UI from some external system which is not possible in appian. As Stefan suggested, we will push back the requirement.