You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Stephan Koch <sk...@remove-n0spam.sk-dev.com> on 2008/03/14 17:56:25 UTC

DateTextField and OnChangeAjaxBehavior

Hi all,

I'm currently having some trouble with a DateTextField. The 
DateTextField has a DatePicker component attached to it.
Once the user changes the date with the DatePicker, the attached 
DateTextField is assigned the new date and should trigger the onChange 
event. Which it doesn't do....

Everything works fine if the date is changed by typing directly it into 
the textfield. Any ideas?




DateTextField dtf  = DateTextField.forShortStyle("dateField", new
PropertyModel(this, "date"));

dtf.add(new DatePicker());

OnChangeAjaxBehavior dateOnChange = new OnChangeAjaxBehavior() {
	
	    @Override
             protected void onUpdate(AjaxRequestTarget target) {
                 log.debug("dateField onChange event triggered.");
		// do some stuff with the date here...
             }

};

dtf.add(dateOnChange);
add(dtf);


--Stephan

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: DateTextField and OnChangeAjaxBehavior

Posted by Stephan Koch <sk...@remove-n0spam.sk-dev.com>.
My bad. I used OnChangeAjaxBehavior instead of AjaxEventBehavior, it 
works perfectly now.
I will file a jira issue for the bug though.

AjaxEventBehavior dateOnChange = new AjaxEventBehavior("onchange") {
            @Override
            protected void onEvent(AjaxRequestTarget target) {

-stephan

Igor Vaynberg wrote:
> On Fri, Mar 14, 2008 at 11:00 AM, Stephan Koch
> <sk...@remove-n0spam.sk-dev.com> wrote:
>   
>> So basically I could subclass DatePicker and override
>>  getAdditionalJavascript to inject some Js that triggers the onchange
>>  event in DateTextField when some useful event in DatePicker fires.
>>     
>
> thats the idea.
>
>   
>>  I also found the appendToInit method below, but that method is never
>>  called in DatePicker. Would that be a bug?
>>     
>
> yes, please file a jira issue
>
> -igor
>
>   
>>  --stephan
>>
>>  /**
>>      * Append javascript to the initialization function for the YUI
>>  widget. Can be used by
>>      * subclasses to conveniently extend configuration without having to
>>  write a separate
>>      * contribution.
>>      *
>>      * @param markupId
>>      *            The markup id of the calendar component
>>      * @param javascriptId
>>      *            the non-name spaced javascript id of the widget
>>      * @param javascriptWidgetId
>>      *            the name space id of the widget
>>      * @param b
>>      *            the buffer to append the script to
>>      */
>>     protected void appendToInit(String markupId, String javascriptId,
>>  String javascriptWidgetId,
>>             StringBuffer b)
>>     {
>>     }
>>
>>  /**
>>      * Override this method to further customize the YUI Calendar with
>>  additional Javascript code.
>>      * The code returned by this method is executed right after the
>>  Calendar has been constructed
>>      * and initialized. To refer to the actual Calendar DOM object, use
>>  <code>${calendar}</code>
>>      * in your code.<br/>See <a
>>  href="http://developer.yahoo.com/yui/calendar/">the widget's
>>      * documentation</a> for more information about the YUI
>>  Calendar.<br/> Example:
>>      *
>>      * <pre>
>>      * protected String getAdditionalJavascript()
>>      * {
>>      *     return &quot;${calendar}.addRenderer(\&quot;10/3\&quot;,
>>  ${calendar}.renderCellStyleHighlight1);&quot;;
>>      * }
>>      * </pre>
>>      *
>>      * @return a String containing additional Javascript code
>>      *
>>      */
>>     protected String getAdditionalJavascript()
>>     {
>>         return "";
>>
>>
>>     }
>>
>>  Igor Vaynberg wrote:
>>  > i dont think values changed via js send out onchange events. you will
>>  > probably need to hook into the datepicker javascript and invoke
>>  > onchange explicitly. fortunately yui stuff has a pretty good event
>>  > system that widgets use, so plugging into it should probably not pose
>>  > a huge problem.
>>  >
>>  > -igor
>>  >
>>  >
>>  > On Fri, Mar 14, 2008 at 9:56 AM, Stephan Koch
>>  > <sk...@remove-n0spam.sk-dev.com> wrote:
>>  >
>>  >> Hi all,
>>  >>
>>  >>  I'm currently having some trouble with a DateTextField. The
>>  >>  DateTextField has a DatePicker component attached to it.
>>  >>  Once the user changes the date with the DatePicker, the attached
>>  >>  DateTextField is assigned the new date and should trigger the onChange
>>  >>  event. Which it doesn't do....
>>  >>
>>  >>  Everything works fine if the date is changed by typing directly it into
>>  >>  the textfield. Any ideas?
>>  >>
>>  >>
>>  >>
>>  >>
>>  >>  DateTextField dtf  = DateTextField.forShortStyle("dateField", new
>>  >>  PropertyModel(this, "date"));
>>  >>
>>  >>  dtf.add(new DatePicker());
>>  >>
>>  >>  OnChangeAjaxBehavior dateOnChange = new OnChangeAjaxBehavior() {
>>  >>
>>  >>             @Override
>>  >>              protected void onUpdate(AjaxRequestTarget target) {
>>  >>                  log.debug("dateField onChange event triggered.");
>>  >>                 // do some stuff with the date here...
>>  >>              }
>>  >>
>>  >>  };
>>  >>
>>  >>  dtf.add(dateOnChange);
>>  >>  add(dtf);
>>  >>
>>  >>
>>  >>  --Stephan
>>  >>
>>  >>  ---------------------------------------------------------------------
>>  >>  To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>  >>  For additional commands, e-mail: users-help@wicket.apache.org
>>  >>
>>  >>
>>  >>
>>  >
>>  > ---------------------------------------------------------------------
>>  > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>  > For additional commands, e-mail: users-help@wicket.apache.org
>>  >
>>  >
>>
>>
>>  ---------------------------------------------------------------------
>>  To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>  For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>>     
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: DateTextField and OnChangeAjaxBehavior

Posted by Igor Vaynberg <ig...@gmail.com>.
On Fri, Mar 14, 2008 at 11:00 AM, Stephan Koch
<sk...@remove-n0spam.sk-dev.com> wrote:
> So basically I could subclass DatePicker and override
>  getAdditionalJavascript to inject some Js that triggers the onchange
>  event in DateTextField when some useful event in DatePicker fires.

thats the idea.

>  I also found the appendToInit method below, but that method is never
>  called in DatePicker. Would that be a bug?

yes, please file a jira issue

-igor

>
>  --stephan
>
>  /**
>      * Append javascript to the initialization function for the YUI
>  widget. Can be used by
>      * subclasses to conveniently extend configuration without having to
>  write a separate
>      * contribution.
>      *
>      * @param markupId
>      *            The markup id of the calendar component
>      * @param javascriptId
>      *            the non-name spaced javascript id of the widget
>      * @param javascriptWidgetId
>      *            the name space id of the widget
>      * @param b
>      *            the buffer to append the script to
>      */
>     protected void appendToInit(String markupId, String javascriptId,
>  String javascriptWidgetId,
>             StringBuffer b)
>     {
>     }
>
>  /**
>      * Override this method to further customize the YUI Calendar with
>  additional Javascript code.
>      * The code returned by this method is executed right after the
>  Calendar has been constructed
>      * and initialized. To refer to the actual Calendar DOM object, use
>  <code>${calendar}</code>
>      * in your code.<br/>See <a
>  href="http://developer.yahoo.com/yui/calendar/">the widget's
>      * documentation</a> for more information about the YUI
>  Calendar.<br/> Example:
>      *
>      * <pre>
>      * protected String getAdditionalJavascript()
>      * {
>      *     return &quot;${calendar}.addRenderer(\&quot;10/3\&quot;,
>  ${calendar}.renderCellStyleHighlight1);&quot;;
>      * }
>      * </pre>
>      *
>      * @return a String containing additional Javascript code
>      *
>      */
>     protected String getAdditionalJavascript()
>     {
>         return "";
>
>
>     }
>
>  Igor Vaynberg wrote:
>  > i dont think values changed via js send out onchange events. you will
>  > probably need to hook into the datepicker javascript and invoke
>  > onchange explicitly. fortunately yui stuff has a pretty good event
>  > system that widgets use, so plugging into it should probably not pose
>  > a huge problem.
>  >
>  > -igor
>  >
>  >
>  > On Fri, Mar 14, 2008 at 9:56 AM, Stephan Koch
>  > <sk...@remove-n0spam.sk-dev.com> wrote:
>  >
>  >> Hi all,
>  >>
>  >>  I'm currently having some trouble with a DateTextField. The
>  >>  DateTextField has a DatePicker component attached to it.
>  >>  Once the user changes the date with the DatePicker, the attached
>  >>  DateTextField is assigned the new date and should trigger the onChange
>  >>  event. Which it doesn't do....
>  >>
>  >>  Everything works fine if the date is changed by typing directly it into
>  >>  the textfield. Any ideas?
>  >>
>  >>
>  >>
>  >>
>  >>  DateTextField dtf  = DateTextField.forShortStyle("dateField", new
>  >>  PropertyModel(this, "date"));
>  >>
>  >>  dtf.add(new DatePicker());
>  >>
>  >>  OnChangeAjaxBehavior dateOnChange = new OnChangeAjaxBehavior() {
>  >>
>  >>             @Override
>  >>              protected void onUpdate(AjaxRequestTarget target) {
>  >>                  log.debug("dateField onChange event triggered.");
>  >>                 // do some stuff with the date here...
>  >>              }
>  >>
>  >>  };
>  >>
>  >>  dtf.add(dateOnChange);
>  >>  add(dtf);
>  >>
>  >>
>  >>  --Stephan
>  >>
>  >>  ---------------------------------------------------------------------
>  >>  To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>  >>  For additional commands, e-mail: users-help@wicket.apache.org
>  >>
>  >>
>  >>
>  >
>  > ---------------------------------------------------------------------
>  > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>  > For additional commands, e-mail: users-help@wicket.apache.org
>  >
>  >
>
>
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>  For additional commands, e-mail: users-help@wicket.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: DateTextField and OnChangeAjaxBehavior

Posted by Stephan Koch <sk...@remove-n0spam.sk-dev.com>.
So basically I could subclass DatePicker and override 
getAdditionalJavascript to inject some Js that triggers the onchange 
event in DateTextField when some useful event in DatePicker fires.

I also found the appendToInit method below, but that method is never 
called in DatePicker. Would that be a bug?

--stephan

/**
     * Append javascript to the initialization function for the YUI 
widget. Can be used by
     * subclasses to conveniently extend configuration without having to 
write a separate
     * contribution.
     *
     * @param markupId
     *            The markup id of the calendar component
     * @param javascriptId
     *            the non-name spaced javascript id of the widget
     * @param javascriptWidgetId
     *            the name space id of the widget
     * @param b
     *            the buffer to append the script to
     */
    protected void appendToInit(String markupId, String javascriptId, 
String javascriptWidgetId,
            StringBuffer b)
    {
    }

/**
     * Override this method to further customize the YUI Calendar with 
additional Javascript code.
     * The code returned by this method is executed right after the 
Calendar has been constructed
     * and initialized. To refer to the actual Calendar DOM object, use 
<code>${calendar}</code>
     * in your code.<br/>See <a 
href="http://developer.yahoo.com/yui/calendar/">the widget's
     * documentation</a> for more information about the YUI 
Calendar.<br/> Example:
     *
     * <pre>
     * protected String getAdditionalJavascript()
     * {
     *     return &quot;${calendar}.addRenderer(\&quot;10/3\&quot;, 
${calendar}.renderCellStyleHighlight1);&quot;;
     * }
     * </pre>
     *
     * @return a String containing additional Javascript code
     *
     */
    protected String getAdditionalJavascript()
    {
        return "";
    }

Igor Vaynberg wrote:
> i dont think values changed via js send out onchange events. you will
> probably need to hook into the datepicker javascript and invoke
> onchange explicitly. fortunately yui stuff has a pretty good event
> system that widgets use, so plugging into it should probably not pose
> a huge problem.
>
> -igor
>
>
> On Fri, Mar 14, 2008 at 9:56 AM, Stephan Koch
> <sk...@remove-n0spam.sk-dev.com> wrote:
>   
>> Hi all,
>>
>>  I'm currently having some trouble with a DateTextField. The
>>  DateTextField has a DatePicker component attached to it.
>>  Once the user changes the date with the DatePicker, the attached
>>  DateTextField is assigned the new date and should trigger the onChange
>>  event. Which it doesn't do....
>>
>>  Everything works fine if the date is changed by typing directly it into
>>  the textfield. Any ideas?
>>
>>
>>
>>
>>  DateTextField dtf  = DateTextField.forShortStyle("dateField", new
>>  PropertyModel(this, "date"));
>>
>>  dtf.add(new DatePicker());
>>
>>  OnChangeAjaxBehavior dateOnChange = new OnChangeAjaxBehavior() {
>>
>>             @Override
>>              protected void onUpdate(AjaxRequestTarget target) {
>>                  log.debug("dateField onChange event triggered.");
>>                 // do some stuff with the date here...
>>              }
>>
>>  };
>>
>>  dtf.add(dateOnChange);
>>  add(dtf);
>>
>>
>>  --Stephan
>>
>>  ---------------------------------------------------------------------
>>  To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>  For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>>     
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: DateTextField and OnChangeAjaxBehavior

Posted by Igor Vaynberg <ig...@gmail.com>.
i dont think values changed via js send out onchange events. you will
probably need to hook into the datepicker javascript and invoke
onchange explicitly. fortunately yui stuff has a pretty good event
system that widgets use, so plugging into it should probably not pose
a huge problem.

-igor


On Fri, Mar 14, 2008 at 9:56 AM, Stephan Koch
<sk...@remove-n0spam.sk-dev.com> wrote:
> Hi all,
>
>  I'm currently having some trouble with a DateTextField. The
>  DateTextField has a DatePicker component attached to it.
>  Once the user changes the date with the DatePicker, the attached
>  DateTextField is assigned the new date and should trigger the onChange
>  event. Which it doesn't do....
>
>  Everything works fine if the date is changed by typing directly it into
>  the textfield. Any ideas?
>
>
>
>
>  DateTextField dtf  = DateTextField.forShortStyle("dateField", new
>  PropertyModel(this, "date"));
>
>  dtf.add(new DatePicker());
>
>  OnChangeAjaxBehavior dateOnChange = new OnChangeAjaxBehavior() {
>
>             @Override
>              protected void onUpdate(AjaxRequestTarget target) {
>                  log.debug("dateField onChange event triggered.");
>                 // do some stuff with the date here...
>              }
>
>  };
>
>  dtf.add(dateOnChange);
>  add(dtf);
>
>
>  --Stephan
>
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>  For additional commands, e-mail: users-help@wicket.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org