You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by drf <da...@gmail.com> on 2010/10/20 19:14:47 UTC

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

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?

-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Using-JavaScript-to-check-a-field-by-id-when-Wicket-will-change-the-id-tp3004266p3004266.html
Sent from the Users forum mailing list archive at Nabble.com.

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


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

Posted by Igor Vaynberg <ig...@gmail.com>.
only if you or something else calls setoutputmarkupid(true)

-igor

On Wed, Oct 20, 2010 at 10:30 AM, Jeremy Thomerson
<je...@wickettraining.com> wrote:
> On Wed, Oct 20, 2010 at 12:26 PM, Arjun Dhar <dh...@yahoo.com> wrote:
>
>> In my opinion; wicket doesn't mess with the "id" attribute till you tell it
>> to. There are multiple means to change the id. but by default the id is not
>> touched.
>>
>> Note: wicket:id is not the same as "id" of the HTML DOM element. So if you
>> define an "id" in the markup it should stick.
>>
>> As per your quote::
>> "because if the field is controlled by Wicket, the id will change. " -- You
>> can choose what attributes are controlled by wicket. its not like an all or
>> nothing scenario.
>>
>
> Actually, Wicket really does change your markup ID by default.  Try adding a
> field to the page like 'new Label("name", someModel)' and you will end up
> with <input type="text" id="name0" /> or something like that, depending on
> other components on the page, if it's in a repeater, etc.
>
>
> --
> Jeremy Thomerson
> http://wickettraining.com
> *Need a CMS for Wicket?  Use Brix! http://brixcms.org*
>

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


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

Posted by Jeremy Thomerson <je...@wickettraining.com>.
On Wed, Oct 20, 2010 at 12:54 PM, Arjun Dhar <dh...@yahoo.com> wrote:

> @Jeremy : my bad then.
>
> I've never seen the id's come on their own unless I do setmarkupId(true)
>

As Igor pitched in, yes, it will only change *if* you (or something else
like any ajax behavior) calls setOutputMarkupId(true)... which the original
poster obviously must be if he's seeing his ID change.

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

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

Posted by Arjun Dhar <dh...@yahoo.com>.
@Jeremy : my bad then. 

I've never seen the id's come on their own unless I do setmarkupId(true)  or
add it by SimpleAttributeModifier() or tag.put("id", ...) in
onComponent(Tag). I guess i need to check it out again.

thanks.
-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Using-JavaScript-to-check-a-field-by-id-when-Wicket-will-change-the-id-tp3004266p3004324.html
Sent from the Users forum mailing list archive at Nabble.com.

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


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

Posted by Jeremy Thomerson <je...@wickettraining.com>.
On Wed, Oct 20, 2010 at 12:26 PM, Arjun Dhar <dh...@yahoo.com> wrote:

> In my opinion; wicket doesn't mess with the "id" attribute till you tell it
> to. There are multiple means to change the id. but by default the id is not
> touched.
>
> Note: wicket:id is not the same as "id" of the HTML DOM element. So if you
> define an "id" in the markup it should stick.
>
> As per your quote::
> "because if the field is controlled by Wicket, the id will change. " -- You
> can choose what attributes are controlled by wicket. its not like an all or
> nothing scenario.
>

Actually, Wicket really does change your markup ID by default.  Try adding a
field to the page like 'new Label("name", someModel)' and you will end up
with <input type="text" id="name0" /> or something like that, depending on
other components on the page, if it's in a repeater, etc.


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

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

Posted by Arjun Dhar <dh...@yahoo.com>.
In my opinion; wicket doesn't mess with the "id" attribute till you tell it
to. There are multiple means to change the id. but by default the id is not
touched.

Note: wicket:id is not the same as "id" of the HTML DOM element. So if you
define an "id" in the markup it should stick.

As per your quote::
"because if the field is controlled by Wicket, the id will change. " -- You
can choose what attributes are controlled by wicket. its not like an all or
nothing scenario.
-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Using-JavaScript-to-check-a-field-by-id-when-Wicket-will-change-the-id-tp3004266p3004281.html
Sent from the Users forum mailing list archive at Nabble.com.

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


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

Posted by Jeremy Thomerson <je...@wickettraining.com>.
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*