You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Paolo Donà <pa...@gmail.com> on 2005/11/08 12:11:39 UTC

javascript error during client validation of a RadioGroup

Hi guys,
I'm getting a javascript validation error which prevent me from
submitting a form.
I've got just a RadioGroup and two Radio components inside the form,
the client validation is enabled because I want the user to select one
of the Radios, without preselection enabled. The error is "field has
no properties" and happens in this snippet of js code:

Tapestry.require_field = function(event, fieldId, message)
{
    var field = this.find(fieldId);

    if (field.value.length == 0)
      event.invalid_field(field, message);
}


Here the files I used to test the error...

Html Template (Test.html):

<span jwcid="@Shell" title="Test Page">
<body jwcid="@Body">
<form jwcid="form">
    My Radio:
    <span jwcid="myRadio">
        <input type="radio" jwcid="yes"/> oh yes! -
        <input type="radio" jwcid="no"/> oh no!
    </span>
    <a href="#" jwcid="@LinkSubmit">GO</a>
</form>
<br/>
Message: <span jwcid="message">FAKE_MESSAGE</span>
</body>
</span>

Java Source (Test.java):

package it.archeometra.flotte.presentation;
/**
 * @tapestry.page-specification
 * @tapestry.form id="form" listener="listener:doSubmit"
client-validation-enabled="true"
 * @tapestry.radio-group id="myRadio" selected="ognl:selected"
display-name="literal:My Radio" validators="validators:required"
 * @tapestry.radio id="yes"
value="ognl:@it.archeometra.flotte.presentation.Test@YES"
 * @tapestry.radio id="no"
value="ognl:@it.archeometra.flotte.presentation.Test@NO"
 * @tapestry.insert id="message" value="ognl:message"
 */
public abstract class Test extends org.apache.tapestry.html.BasePage {
    public final static Boolean YES = Boolean.TRUE;
    public final static Boolean NO = Boolean.FALSE;

    public abstract Boolean getSelected();
    public abstract void setSelected(Boolean b);

    public IPage doSubmit(){
        return this;
    }

    public String getMessage(){
        return "you selected: "+getSelected();
    }
}

generated .page file (Test.page):

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE page-specification PUBLIC "-//Apache Software
Foundation//Tapestry Specification 4.0//EN"
"http://jakarta.apache.org/tapestry/dtd/Tapestry_4_0.dtd">
<page-specification class="it.archeometra.flotte.presentation.Test">
  <!--This file has been generated by xdoclet-plugin-tapestry,
a plugin for XDoclet2. Please do not modify this file.
Modify your Tapestry annotations instead (@tapestry tags)
and rerun 'maven xdoclet2' (or your ant xdoclet2 target)
if you don't wanna lose further modifications-->
  <component type="Form" id="form">
    <binding name="listener" value="listener:doSubmit"/>
    <binding name="clientValidationEnabled" value="true"/>
  </component>
  <component type="Insert" id="message">
    <binding name="value" value="ognl:message"/>
  </component>
  <component type="Radio" id="yes">
    <binding name="value"
value="ognl:@it.archeometra.flotte.presentation.Test@YES"/>
  </component>
  <component type="Radio" id="no">
    <binding name="value"
value="ognl:@it.archeometra.flotte.presentation.Test@NO"/>
  </component>
  <component type="RadioGroup" id="myRadio">
    <binding name="selected" value="ognl:selected"/>
    <binding name="displayName" value="literal:My Radio"/>
    <binding name="validators" value="validators:required"/>
  </component>
</page-specification>

The page renders correctly but when i push the "GO" link, the client
validation fails...

Paolo

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


Re: javascript error during client validation of a RadioGroup

Posted by Paolo Donà <pa...@gmail.com>.
Oh, just seen that the generated onsubmit function on my html points to a
'null' field name instead of my 'myRadio'...
Looks like a bug, right?

<script language="JavaScript" type="text/javascript">
Tapestry.register_form('form');
Tapestry.onsubmit('form', function(event) {
Tapestry.require_field(event, 'null', 'Devi inserire un valore per My
Radio.');
});
</script>

Paolo


On 11/8/05, Paolo Donà <pa...@gmail.com> wrote:
> Hi guys,
> I'm getting a javascript validation error which prevent me from
> submitting a form.
> I've got just a RadioGroup and two Radio components inside the form,
> the client validation is enabled because I want the user to select one
> of the Radios, without preselection enabled. The error is "field has
> no properties" and happens in this snippet of js code:
>
> Tapestry.require_field = function(event, fieldId, message)
> {
> var field = this.find(fieldId);
>
> if (field.value.length == 0)
> event.invalid_field(field, message);
> }
>
>
> Here the files I used to test the error...
>
> Html Template (Test.html):
>
> <span jwcid="@Shell" title="Test Page">
> <body jwcid="@Body">
> <form jwcid="form">
> My Radio:
> <span jwcid="myRadio">
> <input type="radio" jwcid="yes"/> oh yes! -
> <input type="radio" jwcid="no"/> oh no!
> </span>
> <a href="#" jwcid="@LinkSubmit">GO</a>
> </form>
> <br/>
> Message: <span jwcid="message">FAKE_MESSAGE</span>
> </body>
> </span>
>
> Java Source (Test.java):
>
> package it.archeometra.flotte.presentation;
> /**
> * @tapestry.page-specification
> * @tapestry.form id="form" listener="listener:doSubmit"
> client-validation-enabled="true"
> * @tapestry.radio-group id="myRadio" selected="ognl:selected"
> display-name="literal:My Radio" validators="validators:required"
> * @tapestry.radio id="yes"
> value="ognl:@it.archeometra.flotte.presentation.Test@YES"
> * @tapestry.radio id="no"
> value="ognl:@it.archeometra.flotte.presentation.Test@NO"
> * @tapestry.insert id="message" value="ognl:message"
> */
> public abstract class Test extends org.apache.tapestry.html.BasePage {
> public final static Boolean YES = Boolean.TRUE;
> public final static Boolean NO = Boolean.FALSE;
>
> public abstract Boolean getSelected();
> public abstract void setSelected(Boolean b);
>
> public IPage doSubmit(){
> return this;
> }
>
> public String getMessage(){
> return "you selected: "+getSelected();
> }
> }
>
> generated .page file (Test.page):
>
> <?xml version="1.0" encoding="utf-8"?>
> <!DOCTYPE page-specification PUBLIC "-//Apache Software
> Foundation//Tapestry Specification 4.0//EN"
> "http://jakarta.apache.org/tapestry/dtd/Tapestry_4_0.dtd">
> <page-specification class="it.archeometra.flotte.presentation.Test">
> <!--This file has been generated by xdoclet-plugin-tapestry,
> a plugin for XDoclet2. Please do not modify this file.
> Modify your Tapestry annotations instead (@tapestry tags)
> and rerun 'maven xdoclet2' (or your ant xdoclet2 target)
> if you don't wanna lose further modifications-->
> <component type="Form" id="form">
> <binding name="listener" value="listener:doSubmit"/>
> <binding name="clientValidationEnabled" value="true"/>
> </component>
> <component type="Insert" id="message">
> <binding name="value" value="ognl:message"/>
> </component>
> <component type="Radio" id="yes">
> <binding name="value"
> value="ognl:@it.archeometra.flotte.presentation.Test@YES"/>
> </component>
> <component type="Radio" id="no">
> <binding name="value"
> value="ognl:@it.archeometra.flotte.presentation.Test@NO"/>
> </component>
> <component type="RadioGroup" id="myRadio">
> <binding name="selected" value="ognl:selected"/>
> <binding name="displayName" value="literal:My Radio"/>
> <binding name="validators" value="validators:required"/>
> </component>
> </page-specification>
>
> The page renders correctly but when i push the "GO" link, the client
> validation fails...
>
> Paolo
>