You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Julian Wood <wo...@ucalgary.ca> on 2008/03/24 22:32:54 UTC

Select box and validation

The situation is this:

I have a select box in a form, and I want to make it required.

This is simple enough, but the blank option disappears when the  
required validation is applied, client-side validation is not  
performed, and is indeed not needed, because there are no blank  
values. As a corollary, the first option is always selected by default  
upon entry into the form.

The problem with this is that users have a tendency to skip these  
fields which are prepopulated, something which when having a blank  
option does not happen, so this is not the behaviour that I want.

So to change this, I added t:blankoption="always" to the select field,  
to restore the blank option. But now, I am bitten by the previous  
conclusion that client-side validation is not performed on these  
fields (in fact there is no client-side validation at all, ever - the  
paradigm explained here is used to cover the required case). So when  
combined with other fields which do have client-side validation, this  
looks quite disjointed.

So I'm trying to figure out the best way to accomplish what I want,  
which is a select box with a blank option, which has a client-side  
required validation inline with the other client-side required  
validations.

All that is required is the contribution to the  
Tapestry.validate(...)  javascript code snippet by the select field,  
to get it to behave as wanted, but I can't figure out the proper  
mechanism for accomplishing this. I'm sure it's something very simple,  
somewhere, but what?

I can see how it is added -  
org 
.apache 
.tapestry.internal.services.ClientBehaviorSupportImpl#addValidation,  
coming from org.apache.tapestry.validator.Required#render but why is  
render called for a TextField with the 'required' validator, but not  
from a Select field?

Anyway, I'm still digging, but maybe someone has a hint. Thanks,

J



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


Re: Select box and validation

Posted by Julian Wood <wo...@ucalgary.ca>.
So to finish this thread, the workaround is to create your own  
component, copy the entire Select component source, and make one change:

     void beginRender(MarkupWriter writer) {
         writer.element("select", "name", getControlName(), "id",  
getClientId());
         _validate.render(writer);
         _resources.renderInformalParameters(writer);
     }

That _validate.render(writer) is new. Is this the recommended way for  
"extending" components, which I know we're not supposed to (and  
can't) do?

In any case, I feel this behaviour should at least be allowed by the  
Select component, if not made the default, without having to resort  
to this solution.

I've filed a JIRA:

https://issues.apache.org/jira/browse/TAPESTRY-2295

J

On 24-Mar-08, at 3:32 PM, Julian Wood wrote:

> The situation is this:
>
> I have a select box in a form, and I want to make it required.
>
> This is simple enough, but the blank option disappears when the  
> required validation is applied, client-side validation is not  
> performed, and is indeed not needed, because there are no blank  
> values. As a corollary, the first option is always selected by  
> default upon entry into the form.
>
> The problem with this is that users have a tendency to skip these  
> fields which are prepopulated, something which when having a blank  
> option does not happen, so this is not the behaviour that I want.
>
> So to change this, I added t:blankoption="always" to the select  
> field, to restore the blank option. But now, I am bitten by the  
> previous conclusion that client-side validation is not performed on  
> these fields (in fact there is no client-side validation at all,  
> ever - the paradigm explained here is used to cover the required  
> case). So when combined with other fields which do have client-side  
> validation, this looks quite disjointed.
>
> So I'm trying to figure out the best way to accomplish what I want,  
> which is a select box with a blank option, which has a client-side  
> required validation inline with the other client-side required  
> validations.
>
> All that is required is the contribution to the Tapestry.validate 
> (...)  javascript code snippet by the select field, to get it to  
> behave as wanted, but I can't figure out the proper mechanism for  
> accomplishing this. I'm sure it's something very simple, somewhere,  
> but what?
>
> I can see how it is added -  
> org.apache.tapestry.internal.services.ClientBehaviorSupportImpl#addVal 
> idation, coming from org.apache.tapestry.validator.Required#render  
> but why is render called for a TextField with the 'required'  
> validator, but not from a Select field?
>
> Anyway, I'm still digging, but maybe someone has a hint. Thanks,
>
> J
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


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