You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Dan12321 <we...@centrum.cz> on 2012/06/30 13:39:15 UTC

how to connect elements - label and input (checkbox)

Hi,
is there any easy way, how can I connect label and input(checkbox) in
repeater?



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/how-to-connect-elements-label-and-input-checkbox-tp4650304.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: how to connect elements - label and input (checkbox)

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

Please attach a quickstart that reproduce this in a ticket in JIRA.
Thanks!

Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov

On Wed, Oct 1, 2014 at 6:49 AM, miguel <mi...@thedeanda.com> wrote:

> wow this is the strangest thing. i searched for the same thing a year later
> (to the day almost) and again its a silly "agree to terms" checkbox and
> guess what... wicket 6.17.0 seems to have the same problem...
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/how-to-connect-elements-label-and-input-checkbox-tp4650304p4667770.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: how to connect elements - label and input (checkbox)

Posted by miguel <mi...@thedeanda.com>.
wow this is the strangest thing. i searched for the same thing a year later
(to the day almost) and again its a silly "agree to terms" checkbox and
guess what... wicket 6.17.0 seems to have the same problem...

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/how-to-connect-elements-label-and-input-checkbox-tp4650304p4667770.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: how to connect elements - label and input (checkbox)

Posted by miguel <mi...@thedeanda.com>.
aha! it seems that the first time it renders it doesn't include the id in the
checkbox. when it fails validation, the id appears and the label works as
expected. i'll dig into the code when i get a chance.



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/how-to-connect-elements-label-and-input-checkbox-tp4650304p4661649.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: how to connect elements - label and input (checkbox)

Posted by miguel <mi...@thedeanda.com>.
I found this searching for the same answer and my existing code was:

<input type="checkbox" wicket:id="acceptTerms"/>
<label wicket:for="acceptTerms">I agree to the terms</label>

but the output is:

<input type="checkbox" name="acceptTerms" id="acceptTerms5"/>
<label for="acceptTerms5">I agree to the terms</label>

but sometimes it seems that the id isn't set on the checkbox. I'm still
trying to figure out why. (using 6.10 still)



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/how-to-connect-elements-label-and-input-checkbox-tp4650304p4661648.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: how to connect elements - label and input (checkbox)

Posted by Dan Retzlaff <dr...@gmail.com>.
The easiest way is probably to use a wicket:for attribute:
<label wicket:for="enabledCheck">Enabled</label>
<input type="checkbox" wicket:id="enabledCheck"/>

Alternatively, you can also use FormComponent#setLabel(IModel<String>) in
Java to define an input's label value, then show that label by adding
(Simple)FormComponentLabel as a separate component (i.e. with its own
wicket:id).

On Sat, Jun 30, 2012 at 9:13 AM, Dan12321 <we...@centrum.cz> wrote:

> Hi,
> when I click on text in  element, it select or unselect checkbox. But I
> need
> to set attribute "for" in label and attribute "id" in checkbox input.
> I use it in repeater. So I have to generate random text for this
> attributes.
> Is there any better way how to do it?
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/how-to-connect-elements-label-and-input-checkbox-tp4650304p4650308.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: how to connect elements - label and input (checkbox)

Posted by Dan12321 <we...@centrum.cz>.
Hi,
when I click on text in  element, it select or unselect checkbox. But I need
to set attribute "for" in label and attribute "id" in checkbox input.
I use it in repeater. So I have to generate random text for this attributes.
Is there any better way how to do it?

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/how-to-connect-elements-label-and-input-checkbox-tp4650304p4650308.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: how to connect elements - label and input (checkbox)

Posted by yesotaso <ye...@yahoo.com>.
I am not exactly sure if it is what you want but I used a decoretor for
labeling task.
public class SimpleDecorator extends Behavior implements
IAjaxRegionMarkupIdProvider{
	@Override
	public String getAjaxRegionMarkupId(Component component){
// This method is overriden from IAjaxRegionMarkupIdProvider see its
@JavaDoc for details
		return component.getMarkupId() + "_fd";
	}

	@Override
	public void bind(Component component) {
		component.setOutputMarkupId(true);
	}

	@Override
	public void beforeRender(Component component) {
		FormComponent&lt;?> fc = (FormComponent&lt;?>) component;
		Response r = component.getResponse();
		String label = (fc.getLabel() != null) ? fc.getLabel().getObject()	: null;

		if(fc.getParent() instanceof FormComponent&lt;?>) {
			label = null;
		}

		if (label != null) {
			r.write("<label for=\&quot;&quot;);
			r.write(fc.getMarkupId());
			r.write(&quot;\&quot;&quot;);
			if (fc.isValid() == false) {
				r.write(&quot; class=\&quot;error\&quot;&quot;);
			}
			r.write(&quot;>");
			r.write(Strings.escapeMarkup(label));
			if (fc.isRequired()) {
// You can put a "*" or something else if field is required
			}
			r.write("&lt;/label>");
		}
		super.beforeRender(component);
	}
	@Override
	public void afterRender(Component component) {
		Response r = component.getResponse();
		r.write("&lt;/div>");
	}

	@Override
	public void onComponentTag(Component component, ComponentTag tag) {
// If you want to put some css stuff etc for more striking invalid
visuals...
		FormComponent&lt;?> fc = (FormComponent&lt;?>) component;
		if (fc.isValid() == false) {
			String cl = tag.getAttribute("class");
			if (cl == null) {
				tag.put("class", "error");
			} else {
				tag.put("class", "error " + cl);
			}
		}
	}
}

And usage is 
... add(new TextField("someId").setLabel(Model.of("I'm a label")).add(new
SimpleDecorator()))

I believe this is from _Wicket Cookbook_ or _Wicket In Action_ I cant
recall. For checkbox etc you can omit invalid input etc... but idea is the
same.
You can also omit adding behavior and add it later via visitor. I hope it
helps.

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/how-to-connect-elements-label-and-input-checkbox-tp4650304p4650386.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: how to connect elements - label and input (checkbox)

Posted by Andrea Del Bene <an...@gmail.com>.
Hi,

what do you mean exactly with "connect" the two component?
> Hi,
> is there any easy way, how can I connect label and input(checkbox) in
> repeater?
>
>
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/how-to-connect-elements-label-and-input-checkbox-tp4650304.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
>



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