Home General Discussion

No notification displayed when max length of a field is reached or exceeded

Carol_LeeCarol_Lee Customer IT Monkey ✭

We are currently on 9.6.0.2016, and a user complained about the lack of notification as he typed when he reached the maximum number of characters. What upset him is the text got truncated after saving the CR.

Someone brought this up in 2017 too, https://community.cireson.com/discussion/3265/request-that-an-error-notification-be-displayed-if-the-max-length-of-a-field-is-exceeded. May I know if this feature is now available in version 10.2? Please advise.

Answers

  • Tony_CollettTony_Collett Cireson Support Super IT Monkey ✭✭✭✭✭

    I'm running 10.2.1 in my lab and have tested this. Currently fields are limited to their specific length (i.e. description has 4000) and cannot have any more text added to them.

    There's no error notification, but text will stop being added to the field.

  • Carol_LeeCarol_Lee Customer IT Monkey ✭

    Hi @Tony_Collett, thank you so much for info.

  • Konstantin_Slavin-BoKonstantin_Slavin-Bo Customer Ninja IT Monkey ✭✭✭✭

    I'm using this, which adds a text count to all text prompts with a set maxLength on more than 199 chars, ie more than 1 line:

    $(document).ready(function (){
     // Add char counter to text fields on ROs
     if (document.URL.indexOf("ServiceCatalog/RequestOffering") > -1) { // Only worry about RO forms
       // Get all text boxes
       var textAreas = $('[id^=textArea]');
    
       for (var i = 0; i < textAreas.length; i++) {
    
         // We need both obj and element
         var thisTextAreaObj = $(textAreas[i]);
         var thisTextAreaElm = textAreas[i];
    
         // if Limit String Length is not set on RO, the maxLength attr is missing,
         // so assume the class property is the standard max 256 chars, and treat
         // it as a single line text prompt
         if(thisTextAreaElm.maxLength == -1)
           thisTextAreaElm.maxLength = 199;
    
         var maxLength = thisTextAreaElm.maxLength;
    
         // Only add counter to > 1-line prompts
         if(maxLength > 199) {
    
           // Create a div for holding the remaing char count
           thisTextAreaObj.after('<div id="charCountOf'+thisTextAreaElm.id+'" align="right">'+maxLength+'</div>');
    
           // Listen in on the key up event
           thisTextAreaObj.on('keyup', function() {
             // Update text in div
             $('#charCountOf' + this.id).text(this.maxLength - this.value.length);
           });
         }
    
         // If the lenght is less than 199, we have a single line text prompt, so
         // disable Enter key event
         else if(maxLength > -1) {
           thisTextAreaObj.keydown(function(event){if(event.which == 13 ){event.preventDefault();}}).keyup(function(event){if(event.which == 13 ){event.preventDefault();}});
         }
       }
     }
    }
    

    If there's no max length set, the code assumes it's a 1-line prompt, sets the max length to be 199 chars and disables the Enter-key, so there's no line-breaks in 1-line prompt.

  • Konstantin_Slavin-BoKonstantin_Slavin-Bo Customer Ninja IT Monkey ✭✭✭✭

    Oh, I realized this post is probably not about ROs. Nevermind then :)

Sign In or Register to comment.