You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Jeremy Thomerson <je...@wickettraining.com> on 2010/10/20 19:23:43 UTC

Re: Using JavaScript to check a field by id, when Wicket will change the id

On Wed, Oct 20, 2010 at 12:14 PM, drf <da...@gmail.com> wrote:

>
> In our application, we want to do the following:
> 1) Keep a hidden field in a form with a specified id
> 2) At a certain point in the app,  change the value of the field (or hide
> it
> completely using setVisible(false)).
> 3) In the onClick javascript event of a link,  check either the existence
> of
> the field or it's value using document.getElementById().
>
> This way, we can determine whether or not to bring up a dialog box.
>
> But how?
> 1) We cannot use the id to get the hidden field, because if the field is
> controlled by Wicket, the id will change.
> 2) If the hidden field is not controlled by Wicket, we cannot change
> anything about it (like say setVisible(), or changing it's class attribute
> using AttributeModifier).
>
> What is the best way to do this?
>
>
Call setMarkupId("foo") on it.  Or, even better, is to include your JS as a
behavior that uses the markup ID generated by Wicket.  i.e:

hiddenField.add(new AbstractBehavior() {
  onRenderHead(IHeaderResponse resp) {
    resp.addOnDomReadyJavaScript("some-script");
  }
});

-- 
Jeremy Thomerson
http://wickettraining.com
*Need a CMS for Wicket?  Use Brix! http://brixcms.org*