I have a very simple form and I'm trying to add a special class to a div
inside the form which would indicate if the field that's contained inside
the div has an error. It seems that it should be simple to do so, but I
can't seem to do it.

I'm trying to style the form using the Bootstrap form styles (
http://twitter.github.com/bootstrap/). In summary, in order to mark a field
as in error, I need to be able to add an extra class to otherwise quite
regular markup, e.g. :

<t:form t:id="companyForm" class="well form-horizontal" t:validate="this"
clientValidation="false">
    <fieldset>
        <div class="control-group  [--- This is where I need to put an
'error' class if the field has an error --] ">
            <t:label class="control-label" for="companyNameField">Company
Name</t:label>
            <div class="controls" >
                <input  class="input-medium" placeholder="Company Name"
t:type="textField" t:id="companyNameField" t:value="companyName"
t:validate="required,minlength=3, maxlength=100"/>
                <span class="help-inline">
                    <t:error for="companyNameField" />
                </span>
            </div>
        </div>

    </fieldset>
</t:form>

Sounds like it should be simple enough, but so far I have been unable to
make it produce an error class in the place of the  [--- This is where I
need to put an 'error' class if the field has an error --] placeholder.
What I tried:

1. Added a method on the page "getCompanyNameFieldClass()" and added <div
class="control-group ${getCompanyNameFieldClass()}"> . The implementation
of the method basically is a one liner (after a bunch of null checks) that
returns a string based on
 "companyForm.getDefaultTracker().inError(companyNameField)" . This always
returns false.

2. Injected @Environmental @Property private ValidationTracker into the
page, then attempted the same on the page int he curly braces , e.g.
${validationTracker.isError(companyNameField)}, which is always false.
Interestingly enough, right next to it, I have an "t:error" component which
seems to properly render the error from the field. Similarly,
validationTracker.getHasErrors() seems to return true when there is an
error - just not when I pass the field in.

This seems like it should be very simple; yet, I can't seem to find
anything in the docs or an example of how this could be done. The thing
that comes the closest seems to be the Jumpstart "No Validation Bubbles"
example (
http://jumpstart.doublenegative.com.au/jumpstart/examples/input/novalidationbubbles1)
but it seems like an overkill to have to extend a component and do crazy
things w/ the validation decorator for something this simple.

I took at peek at the Tapestry bootstrap integration module, but so far I
haven't been able to make heads or tails of where something similar might
be happening there.

Can someone point me what direction I should be looking at ? This should be
simple, right ?

Cheers,

Alex K

Reply via email to