ICEfaces
  1. ICEfaces
  2. ICE-6636

2.0 prevents custom javascript from cancelling keyboard stroke in IE

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0.0, 2.0.0-EE-Beta1
    • Fix Version/s: 2.0.1
    • Component/s: ICE-Components
    • Labels:
      None
    • Environment:
      IE7/8
    • Workaround Exists:
      Yes
    • Workaround Description:
      Use onkeydown instead of onkeypress.

      Description

      The customer has a custom javascript solution that allows for only numbers to be entered in an ice:inputText component like so:

       <ice:inputText onkeypress="return numbersonly(this, event);"/>

      The javascript solution can be found here: http://www.htmlcodetutorial.com/forms/index_famsupp_158.html. This solution works in 1.8.2 P02 and a stock JSF 2.0 example on FF and IE. However, this does not work in 2.0 or 2.0 EE Beta with IE7 or 8. It does work in FF.

      The workaround is to use onkeydown but the customer has mentioned that they have existing logic in this event.

      2.0 EE Beta (sc9836_IF2.war) and stock JSF 2 (case9836Example.war) test cases are attached.

        Activity

        Hide
        Mircea Toma added a comment -

        The attached caps.js file contains a modified definition for numbersonly() function. The function cancels the default action for the event internally, invoking either event.preventDefault() function in Firefox/Safari/Opera or sets the event.returnValue property to false in case of IE.

        Show
        Mircea Toma added a comment - The attached caps.js file contains a modified definition for numbersonly() function. The function cancels the default action for the event internally, invoking either event.preventDefault() function in Firefox/Safari/Opera or sets the event.returnValue property to false in case of IE.
        Hide
        Mircea Toma added a comment -

        The reason why the default action is not canceled seems to be caused by the way IE evaluates the inlined event handler code.

        In the rendered markup the 'keypress' event handler looks like this:
        onkeypress="return numbersonly(this, event); iceSubmit(form,this,event);"

        In Firefox/Safari the first statement is evaluated, normally the second statement is not reachable but it seems that these browsers choose to evaluate the remaining statements as well. The proof is that when 'Enter' is pressed the iceSubmit() function is executed. The value returned by numbersonly() is returned back to the browser.

        In IE the both statements are executed as well but the event handler code doesn't return the numbersonly() return value since it 's not the last statement.

        So, the solution to this issue is to cancel the default action using preventDefault/returnValue API since controlling the order of statements in the in the inline event handler is not possible (iceSubmit(...) will always be rendered last).

        To completely solve the issue the caps.js code needs to be replaced with the attached version and ice:inputText's onkeypress attribute needs to be modified as follows:

        <ice:inputText id="step1DriverSSNP1IPText" onkeypress="numbersonly(this, event);"/>

        Show
        Mircea Toma added a comment - The reason why the default action is not canceled seems to be caused by the way IE evaluates the inlined event handler code. In the rendered markup the 'keypress' event handler looks like this: onkeypress="return numbersonly(this, event); iceSubmit(form,this,event);" In Firefox/Safari the first statement is evaluated, normally the second statement is not reachable but it seems that these browsers choose to evaluate the remaining statements as well. The proof is that when 'Enter' is pressed the iceSubmit() function is executed. The value returned by numbersonly() is returned back to the browser. In IE the both statements are executed as well but the event handler code doesn't return the numbersonly() return value since it 's not the last statement. So, the solution to this issue is to cancel the default action using preventDefault/returnValue API since controlling the order of statements in the in the inline event handler is not possible (iceSubmit(...) will always be rendered last). To completely solve the issue the caps.js code needs to be replaced with the attached version and ice:inputText's onkeypress attribute needs to be modified as follows: <ice:inputText id="step1DriverSSNP1IPText" onkeypress="numbersonly(this, event);"/>

          People

          • Assignee:
            Mircea Toma
            Reporter:
            Tyler Johnson
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: