When using a!paragraphField, we have refreshAfter: set to "KEYPRESS".

Certified Senior Developer
When using a!paragraphField, we have refreshAfter: set to "KEYPRESS". We want to limit the character count in the paragraph field, which works by truncating in the saveInto, and we can provide a live character count in the instructions below, however the user may still enter additional characters into the paragraph, and they don't get cut off until the field loses focus (they tab or click outside of it). Is there any way to immediately reflect the truncated value in the paragraph field while they are typing?

OriginalPostID-142471

OriginalPostID-142471

  Discussion posts and replies are publicly visible

  • 0
    Certified Lead Developer
    I think I may have previously implemented something like this with at least some success. Can you post some example code for what you have implemented currently?
  • 0
    Certified Senior Developer
    Example code:

    =load(
              local!value,
              a!paragraphField(
                        label: ri!label,
                        value: local!value,
                        saveInto: {
                                  a!save(ri!output,rule!SAIL_UTIL_limitInputSize(save!value,ri!maxCharacters)),
                                  a!save(local!value,rule!SAIL_UTIL_limitInputSize(save!value,ri!maxCharacters))
                        },
                        validations: {
                                  ri!validations
                        },
                        required: ri!required,
                        instructions: ri!instructions& if(and(not(rule!APN_isBlank(ri!instructions)),not(isnull(ri!maxCharacters))),
                                  " ",
                                  ""
                         )&
                         if(not(isnull(ri!maxCharacters)),
                                  len(local!value) & " of " & ri!maxCharacters & " characters entered. This text field is limited to " & ri!maxCharacters & " characters.",
                                  ""
                                  ),
                        readOnly: ri!readOnly,
                        requiredMessage: ri!requiredMessage,
                        refreshAfter: "KEYPRESS"
    )
    )
  • 0
    Certified Lead Developer
    Whoops, you're right - it seems that no matter what trickery we do within the saveInto{}, the text / paragraph box won't reflect the changes until focus is lost. This smaller code snippet probably reproduces the issue concisely:

    a!textField(
    label: "test",
    value: ri!text,
    refreshAfter: "KEYPRESS",
    disabled: len(ri!text) > 5,
    saveInto: {
    a!save(
    ri!text,
    left(save!value, 5)
    )
    }
    )
  • I think its better to show validation for it rather than disabling paragraph field. Your code became like
    load(
              local!value,
              a!paragraphField(
                        label: ri!label,
                        value: local!value,
                        saveInto: {
                                  a!save(ri!output,rule!SAIL_UTIL_limitInputSize(save!value,ri!maxCharacters)),
                                  a!save(local!value,rule!SAIL_UTIL_limitInputSize(save!value,ri!maxCharacters))
                        },
                        validations: {
                                  if(len(trim(local!value)>100,"Please enter less than 100 letters.","")
                        },
                        required: ri!required,
                        instructions: ri!instructions& if(and(not(rule!APN_isBlank(ri!instructions)),not(isnull(ri!maxCharacters))),
                                  " ",
                                  ""
                         )&
                         if(not(isnull(ri!maxCharacters)),
                                  len(local!value) & " of " & ri!maxCharacters & " characters entered. This text field is limited to " & ri!maxCharacters & " characters.",
                                  ""
                                  ),
                        readOnly: ri!readOnly,
                        requiredMessage: ri!requiredMessage,
                        refreshAfter: "KEYPRESS"
    )
    )
  • 0
    Certified Senior Developer
    We don't want to disable the field, obviously, what we want is to stop accepting additional characters while the user is still type (I.e. truncate the string immediately before they leave the field).
  • Use a!save(local!value,leftb(save!value,100)) for saving of that field value. It will truncate string input as you required and maintained its max length to 100.
  • 0
    Certified Lead Developer
    @sachinr: the issue jason is looking to fix, though, is a way to prevent the user from continuing to type in the text entry box after the size limit has been reached. doing the a!save as you mention does only save the first 100 characters, however it doesn't update the actual contents of the box until they've un-focused. Nothing short of disabling the box actually interrupts the user's input, and disabling is not the desired behavior here. IMHO based on current OOB capabilities, this situation will require compromise on one thing or another.
  • 0
    Certified Senior Developer
    Thanks, all, sounds like it may not be possible. This would be a great enhancement!
  • I have submitted an enhancement request, and the reference number is AN-59443.
  • @jasonr411, Did you find any alternate for this?. We have same requirement.