You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Wes Bramhall <We...@widen.com> on 2006/08/17 00:21:23 UTC

Javascript enabling/disabling validated fields

I've spent the better part of two days attempting to have fields with
validators enabled and disabled through javascript and having it work.

Here's the situation:

I have a form with several fields on it. They are always visible and
required. There is a checkbox that, when clicked, uses javascript to
show another textfield. I want this textfield to be required, using the
required validator. The problem is that I only want it to be validated
or even submitted if the user clicks the checkbox. By default, the field
is disabled. Even if javascript enables the field, it never gets
validated and is always null in my listener. If the field is enabled by
default and I use javascript to disable the field, it always gets
validated, even though it is disabled.

<box jwcid="@Checkbox" value="ognl:fieldChecked"
onclick="ognl:fieldCheckedJavascript"/>Show Field<br />
<div id="fieldDiv" style="display:none">
	<field jwcid="@TextField" id="ognl:fieldId"
value="ognl:optionalRequiredData" disabled="true"
validators="validators:required"/>
</div>

The fieldCheckedJavascript toggles the display value of the fieldDiv to
show/hide the field. It also toggles the disabled property of the
textfield so that it is disabled when hidden and enabled when in view.
The required validator never validates the field, regardless of the
state. If I remove the disabled by default, then the field is always
required, even if set to disabled with the javascript.

I could use some ideas, or let me know if this isn't possible in T4.

Thanks,
-Wes Bramhall

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


Re: Javascript enabling/disabling validated fields

Posted by Jesse Kuhnert <jk...@gmail.com>.
Look at the "Dojo validation profiles" section of this page:

http://tapestry.apache.org/tapestry4.1/javascript/form.html

I haven't added direct support for it (~yet~..it's a JIRA issue though), but
having it check for something like what you described would be covered by
the "dependencies" property.

You can also either add your own custom javascript validation profile to the
client side form (in addition to the profile tapestry sets up for you.)

You can also implement ValidatableFieldExtension in your component directly
(
http://tapestry.apache.org/tapestry4.1/tapestry-framework/apidocs/org/apache/tapestry/form/ValidatableFieldExtension.html)
if you would like to override how an existing validator is configured...

There are many many  possibilities, but quickly adding in to your client
side profile via the client side api call "tapestry.form.registerProfile(form,
profile)" is probably the easiest thing to do. (also covered at
http://tapestry.apache.org/tapestry4.1/javascript/form.html)


On 8/16/06, Wes Bramhall <We...@widen.com> wrote:
>
>
> I've spent the better part of two days attempting to have fields with
> validators enabled and disabled through javascript and having it work.
>
> Here's the situation:
>
> I have a form with several fields on it. They are always visible and
> required. There is a checkbox that, when clicked, uses javascript to
> show another textfield. I want this textfield to be required, using the
> required validator. The problem is that I only want it to be validated
> or even submitted if the user clicks the checkbox. By default, the field
> is disabled. Even if javascript enables the field, it never gets
> validated and is always null in my listener. If the field is enabled by
> default and I use javascript to disable the field, it always gets
> validated, even though it is disabled.
>
> <box jwcid="@Checkbox" value="ognl:fieldChecked"
> onclick="ognl:fieldCheckedJavascript"/>Show Field<br />
> <div id="fieldDiv" style="display:none">
>         <field jwcid="@TextField" id="ognl:fieldId"
> value="ognl:optionalRequiredData" disabled="true"
> validators="validators:required"/>
> </div>
>
> The fieldCheckedJavascript toggles the display value of the fieldDiv to
> show/hide the field. It also toggles the disabled property of the
> textfield so that it is disabled when hidden and enabled when in view.
> The required validator never validates the field, regardless of the
> state. If I remove the disabled by default, then the field is always
> required, even if set to disabled with the javascript.
>
> I could use some ideas, or let me know if this isn't possible in T4.
>
> Thanks,
> -Wes Bramhall
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
Jesse Kuhnert
Tapestry/Dojo/(and a dash of TestNG), team member/developer

Open source based consulting work centered around
dojo/tapestry/tacos/hivemind.