[html-formfu] Asterisking labels of required fields

Carl Franks fireartist at gmail.com
Tue Jun 3 10:39:18 BST 2008


2008/6/3 Georg Oechsler <goe-formfu at space.net>:
> Hi!
>
> I'm wondering how I can make FormFu asterisk the labels of fields which are
> required by constraint.
> I certainly do not want to mark them manually in the yaml file. Is there any way
> to access the constraints of an element from within the TT template files?

Probably the simplest way to do this is to use the CSS pseudo elements
":before" or ":after".
I know they work in firefox, but I haven't tested whether IE7 supports
them (IE6 definitely doesn't).

If you set:
    $form->auto_constraint_class( 'constraint_%t' )
then every field container will get extra classes, corresponding to
it's constraints.
All fields with a Required constraint will get a "constraint_required" class.

Something like this should add the asterix for you:

fieldset .constraint_required label {
  content: '*'
}

Personally, though, I'd prefer to simply use CSS to change the field
or its label's background colour, and use the same colour on a general
'required' notice, at the top of the form - and expect the user to
make the connection.
This has the advantage of not requiring the :before or :after elements.

2008/6/3 Michele Beltrame <mb at cattlegrid.info>:
>
> If you want to do it on a already-created form, you'll need to take a
> look at the INTROSPECTION section of HTML::FormFu documentation:

Unfortunately this won't work within the TT files, as you only get a
dumb data structure, and not access to the original field objects.
There was talk about adding an object() method to the form and all
elements, in the thread "self.form.has_errors in TT templates" - see
the January archives - but this hasn't been implemented yet.

Another option might be to check out the config_callback() feature.

Carl



More information about the HTML-FormFu mailing list