You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Viktor Matić <vi...@inge-mark.hr> on 2007/05/31 11:30:51 UTC

custom js validator T4.0

  Hi,

I have problem with js validator, which looks like:

Tapestry.validate_basket_qty = function(event, fieldId, min, message)
{
     var o = this.find(fieldId);
	var value = o.value;

	if (value == "") return;

     if (Number(value) < min && Number(value) != 0 )
       event.invalid_field(field, message)
}

as it can be seen it is similar to Tapestry min validator with minor  
change (it accepts 0). Script
is placed in our package and it is used by custom validator render  
method which extends BaseValidator.

Page renders correctly and above function is called on form submit,  
but for some reason

     event.invalid_field(field, message)

fails to do the job. Page submits which should not happen. After it  
is submitted server side validation
fires.

Regards,

Viktor Matic




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


Re: custom js validator T4.0

Posted by Viktor Matić <vi...@tel.fer.hr>.
Hi,
On 2007.05.31, at 11:30, Viktor Matić wrote:

>  Hi,
>
> I have problem with js validator, which looks like:
>
> Tapestry.validate_basket_qty = function(event, fieldId, min, message)
> {
>     var o = this.find(fieldId);
> 	var value = o.value;
>
> 	if (value == "") return;
>
>     if (Number(value) < min && Number(value) != 0 )
>       event.invalid_field(field, message)
> }
it seems that default_invalid_field_handler is not registered in  
FormEventManager for forms with custom validator.
I could not find why. So I took ugly shortcut and resolved this issue  
by doing same thing which should be done in
default_invalid_field_handler.

Now js validator looks like this:

Tapestry.validate_basket_qty = function(event, fieldId, min, message)
{
     var o = this.find(fieldId);
	var value = o.value;

	if (value == "") return;

     if (Number(value) < min && Number(value) != 0 )
     {
        Tapestry.set_focus(o);

        window.alert(message);

        event.abort = true;
        event.cancel_handlers = true;
     }
}


> as it can be seen it is similar to Tapestry min validator with  
> minor change (it accepts 0). Script
> is placed in our package and it is used by custom validator render  
> method which extends BaseValidator.
>
> Page renders correctly and above function is called on form submit,  
> but for some reason
>
>     event.invalid_field(field, message)
>
> fails to do the job. Page submits which should not happen. After it  
> is submitted server side validation
> fires.
>
> Regards,
>
> Viktor Matic
>
>
>
>
> ---------------------------------------------------------------------
> 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