ICEfaces
  1. ICEfaces
  2. ICE-5343

ice:inputTextArea allows for strings longer than defined maxlength

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Won't Fix
    • Affects Version/s: 1.8.2
    • Fix Version/s: 1.8.2-EE-GA_P01, 1.8.3
    • Component/s: ICE-Components
    • Labels:
      None
    • Environment:
      Icefaces rev.20220
    • Workaround Exists:
      Yes

      Description

      If user define maxlength then script Ice.txtAreaMaxLen is fired on some events, like below:

      <TEXTAREA onmousedown="this.focus();" onkeydown="Ice.txtAreaMaxLen(this,140);" onblur="iceSubmitPartial(form, this, event);" onchange="Ice.txtAreaMaxLen(this,140);" (...)></TEXTAREA>

      But the same script cannot be fired onkeydown and onchange. Event onkeydown should return false if new char exceeds range

      This patch should helps

      <TEXTAREA onmousedown="this.focus();" onkeydown="return Ice.txtAreaMaxLen(this,140);" onblur="iceSubmitPartial(form, this, event);" onchange="Ice.txtAreaMaxLen(this,140);" (...)></TEXTAREA>

      Ice.txtAreaMaxLen = function(field, maxlength) {
          if (maxlength >= 0) {
             if(field.value.length == maxlength)
                return false;
             if(field.value.length > maxlength)
               field.value = field.value.substring(0, maxlength);
          }
         return true;
      }

        Issue Links

          Activity

          Hide
          Krashan Brahmanjara added a comment - - edited

          In attached file patch for Icefaces rev.20636

          Changes

          \bridge\lib\extras\extras.js
          309c309,312
          < if (maxlength >= 0 && field.value.length > maxlength) {

          > if (maxlength >= 0){
          > if (field.value.length == maxlength)
          > return false;
          > if (field.value.length > maxlength)
          311a315
          > return true;

          \component\src\com\icesoft\faces\component\ext\renderkit\TextareaRenderer.java
          78c78
          < rendererJS.put(HTML.ONKEYDOWN_ATTR, handler);

          > rendererJS.put(HTML.ONKEYDOWN_ATTR, " return "+handler);

          Test case
          component-showcase > textfields.jspx > add maxlength="20" to ice:inputTextarea
          Without patch user can typ 21 chars and last char is truncated only after submit.

          Show
          Krashan Brahmanjara added a comment - - edited In attached file patch for Icefaces rev.20636 Changes \bridge\lib\extras\extras.js 309c309,312 < if (maxlength >= 0 && field.value.length > maxlength) { — > if (maxlength >= 0){ > if (field.value.length == maxlength) > return false; > if (field.value.length > maxlength) 311a315 > return true; \component\src\com\icesoft\faces\component\ext\renderkit\TextareaRenderer.java 78c78 < rendererJS.put(HTML.ONKEYDOWN_ATTR, handler); — > rendererJS.put(HTML.ONKEYDOWN_ATTR, " return "+handler); Test case component-showcase > textfields.jspx > add maxlength="20" to ice:inputTextarea Without patch user can typ 21 chars and last char is truncated only after submit.
          Hide
          Mark Collette added a comment -

          A problem with this approach is that once you've entered the maximum number of allowed characters, you can't use the arrow keys to move the caret around.

          Show
          Mark Collette added a comment - A problem with this approach is that once you've entered the maximum number of allowed characters, you can't use the arrow keys to move the caret around.
          Hide
          Mark Collette added a comment -

          If you look at ICE-3458, you'll see that we intentionally chose to go with the simple solution that works, but doesn't look 100% pretty, over the more complicated approaches, that try to look more correct, but add much more complexity, with the key stroke handling.

          Show
          Mark Collette added a comment - If you look at ICE-3458 , you'll see that we intentionally chose to go with the simple solution that works, but doesn't look 100% pretty, over the more complicated approaches, that try to look more correct, but add much more complexity, with the key stroke handling.
          Hide
          Krashan Brahmanjara added a comment -

          Fixed script for modern browsers.

          Ice.txtAreaMaxLen = function(field, event, maxlength) {
          var key;
          if (window.event)

          { key = window.event.keyCode; }

          else if (event)

          { key = event.which; }

          else

          { return true; }

          // ignore control keys
          if ((key==null) || (key<13) || ((key>=35) && (key<=40)) || (key==91) || (key==92) || (key==93) ) { return true; }

          if (maxlength >= 0){
          if (field.value.length == maxlength) {
          // ignore delete and insert
          if ( (key==46) || (key==45) )

          { return true; }

          else

          { return false; }

          }
          if (field.value.length > maxlength)

          { field.value = field.value.substring(0, maxlength); }


          }
          return true;
          }

          Show
          Krashan Brahmanjara added a comment - Fixed script for modern browsers. Ice.txtAreaMaxLen = function(field, event, maxlength) { var key; if (window.event) { key = window.event.keyCode; } else if (event) { key = event.which; } else { return true; } // ignore control keys if ((key==null) || (key<13) || ((key>=35) && (key<=40)) || (key==91) || (key==92) || (key==93) ) { return true; } if (maxlength >= 0){ if (field.value.length == maxlength) { // ignore delete and insert if ( (key==46) || (key==45) ) { return true; } else { return false; } } if (field.value.length > maxlength) { field.value = field.value.substring(0, maxlength); } } return true; }

            People

            • Assignee:
              Unassigned
              Reporter:
              Krashan Brahmanjara
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: