On Jul 30, 2005, at 04:44, Igor Vaynberg wrote:

This will create a field label that will turn red when the linked form
component has an error.

Another good use is to prepand an asterisk to the fieldlabel's label if the
linked form component has a requiredvalidator added.

I did more or less the same thing the other day. My FieldLabel class does two things: It checks the list of validators attached to the form component (if it's a FormComponent). If the list contains a RequiredValidator, the value "required" is added to the label's class attribute. If the component has feedback messages, I add "error" to the label's class attribute.

I like to keep my html as simple and semantically sound as possible and do all styling in CSS. The actual content of the label is never changed, just the CSS. The relevant CSS could look like this:

label:after           { content: ":"; }
label.required:before { content: "*"; }
label.error           { font-style: italic;  color: red;}

This will render a ":" after every field label. When the label's class is "required", it renders an asterisk in front of the label. Obviously a class of "error" renders the label in red and italic, and the neat thing is that you can apply multiple CSS classes by using a space separated list of names in your class attribute. So <label class="error required">...</label> will render in red and italic, with a '*' in front and a ':' at the end.

Sometimes, a field label is used for multiple fields (credit card number and 3-digit security code, for example, or a 4x4 digit prepaid voucher number field). That's why I added the possiblity to pass an array of components to FieldLabel - the label's appearance will change based on any field in the array.

cheers,
Gert Jan


-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to