6 Replies Latest reply on Apr 24, 2012 9:15 AM by gensys

    inputNumberSpinner behaviour on wrong input

    jiri.pejchal

      I have a table with items that are edited with modal panel. The modal panel contains inputNumberSpinner. When an user enters a non valid value: -9 (too low), 500 (greater than maxValue) and clicks somewhere else the value is set to previous correct value with javascript.

      The problem:
      User is editing previously entered item, he changes the value to an incorrect one and clicks immediately on 'Save' button of the modal window -> he doesn't get notification that his entered value is invalid, the value is changed to previous correct one (-> and validation phase is therefore successful) and saved to a database.

      So actually for example maxValue is saved without user knowing.

      How would you solve it?

        • 1. Re: inputNumberSpinner behaviour on wrong input
          fabmars
          • 2. Re: inputNumberSpinner behaviour on wrong input
            jiri.pejchal

            Section 1.12 is How to prevent modalPanel from closing when the validation inside fails

            But the problem here is that the validation inside the modal panel doesn't fail because the inputNumberSpinner sets silently the correct value with javascript. So actually my goal is to make the validation fail.

            • 3. Re: inputNumberSpinner behaviour on wrong input
              ilya_shaikovsky

              there is onerror js handler on these components. It could be used to execute custom js code if user entered wrong value.

              • 4. Re: inputNumberSpinner behaviour on wrong input
                gensys

                Hello,

                 

                 

                I cannot seem to catch the onerror event. I am also using an InputNumberSpinner inside a modal dialog.

                When I input a value outside of the min-max range and change focus to another component, the value is automatically adjusted to one inside the range.

                I need to catch the event, so I can let the user know what is happening. I am using RichFaces Version 3.3.3 :

                 

                <ui:composition xmlns="http://www.w3.org/1999/xhtml" .....>

                <a4j:form id="numberEditorPanelForm">

                <rich:modalPanel ......>

                 

                    <h:panelGrid ...../>

                 

                        <rich:inputNumberSpinner id="numberValue" style="width: 290px;"

                            value="#{BackingBean.numberValue }"

                            minValue="#{BackingBean.minValue }"

                            maxValue="#{BackingBean.maxValue }"

                            onerror="alert('autocorrect')>

                        </rich:inputNumberSpinner>

                 

                    </h:panelGrid>

                </rich:modalPanel>

                </a4j:form>

                </ui:composition>

                 

                Message was edited by: Gen Sys

                • 5. Re: inputNumberSpinner behaviour on wrong input
                  gensys

                  Hello again,

                   

                  I have been playing with the issue a little bit. I tried to catch the user-input event and compare it to the min & max values so I can provide a meaningful message to the user. However, it turns out that the "oninputkeyup" event is only fired when the input value is within the min-max range, but not when the input value is above or below.

                  The "oninputkeypress" is fired before the new value is applied to the backing bean component. And the"onblur" event is fired after the user-input value is already adjusted to the min or max.

                   

                  Any help or direction would be highly appreciated! Thank you in advance!

                  • 6. Re: inputNumberSpinner behaviour on wrong input
                    gensys

                    Hello,

                     

                    For the moment I have resorted to simply adding an info message in the dialog that notifies the user about the min & max boundaries.

                    This is the best possible solution that I could come up with. I am not handling any events in this situation and I leave the InputNumberSpinner do its auto-correct.

                     

                    If you still have any other suggestions, they are very welcome!

                     

                    Have a nice development day for now!

                     

                    PS: I also put up another thread with a more thorough description of my problem, the "progress" and what I have decided to to in the end:

                    https://community.jboss.org/thread/198734