2 Replies Latest reply on Feb 16, 2010 8:23 PM by Daniel Marzano

    rich:calendar oninputchange event problem

    Daniel Marzano Newbie

      Hello,

       

      I am having this weird issue with the rich:calendar control.

       

      I am using version 3.3.2.SR1of Richfaces. The issue happens in both IE8 and FF 3.5.7, I am using windows XP.

       

       

      The simplified code snippet is:

       

      ...

              <script>
              function parseDate(dateStr) {
                var dateParts = dateStr.split("/");
                    return new Date(dateParts[2],dateParts[1]-1,dateParts[0]);
              }

       

              function validate(el) {
                  // just return true for this demo
                  return true;
              }
             
              </script>
             
              <rich:calendar id="test" datePattern="dd/MM/yyyy"
                enableManualInput="true"
                oninputchange="if (validate) {#{rich:component('test')}.selectDate(parseDate(this.value))}">
                <a4j:support event="onchanged" oncomplete="alert('completed')"/>
              </rich:calendar>

      ...

       

      If I enter a value of "1/12/2010" into the input field and tab out of it the oncomplete event is triggered in the a4j:support tag.

      If I enter a value of "11/12/2010" into the input field and tab out of it no event is triggered, i.e. the alert is not shown.

       

      Any ideas? What I want to basically do is validate the entered data on the client side and if valid trigger off an a4j event.

        • 1. Re: rich:calendar oninputchange event problem
          Ilya Shaikovsky Master

          Very interesting case,. As I gues the goal of your selectDate() statement - to set the date in calendar js object in order to changed event to be risen and your ajax request to be called.

           

          The problem is - selectDate function designed to set some new date from js. So after all the parsing and setting in client objects - it tries to update input itself. But the input already contains the same date And it works for the 2/x/x dates only because pased date which will be setted is 02/x/x and input date 2/x/x - so condition for changed is true and event risen

           

          I suggest you to change the code to this:

           

               <rich:calendar id="test" datePattern="dd/MM/yyyy"
                    enableManualInput="true"
                    oninputchange="if (validate) {ajaxSubmit()}">
                    <a4j:support event="onchanged" oncomplete="alert('completed')"/>
               </rich:calendar> 
               <a4j:jsFunction name="ajaxSubmit">
          
          • 2. Re: rich:calendar oninputchange event problem
            Daniel Marzano Newbie
            Thanks for the reply, I ended up using a <h:inputText> for the manual input which I validate and hidding the input field in the rich:calendar.