You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Alex Kovacs <al...@fast.fujitsu.com.au> on 2004/03/17 06:04:17 UTC

woody2.js: custom validation issue in cocoon-2.1.2 to 2.1.4

I may be wrong, but it seems the current implementation of woody2.js
flowscript has a problem when using custom validation together with the
woody's built-in validation. 

The following is the current fragment in question:
        // Additional flow-level validation
        if (finished && this.form.isValid()) {
            if (this.validator == null) {
              this.isValid = true;
            } else {
              this.isValid = this.validator(this.form, bizData);
              finished = this.isValid;
            }
        }

The "if" statement is evaluated to true only if the form built-in
validation is successful. Therefore, we will not be able to show any
custom validation messages to the user, until she re-submits the form.
IMHO this is not efficient or intuitive to the user. I would rather have
all the invalid fields displaying the associated error messages and ask
the user to correct them in one go. The code could be restructured like
in the following example:

            if (this.validator == null) {
		  //if no custom validation
              this.isValid = this.form.isValid();
            } else {
	          var validated = true;
	          
	          if(!this.validator(this.form, bizData))
	          	validated = false;
	          
	          if(!this.form.isValid())
	          	validated = false;
	          	
              this.isValid = validated;
              finished = this.isValid;
            }

We are using the above fix in our development and we thought it would be
good to have a fix in cocoon so we do not need to patch it every time we
get a new release.

Rgds,
Alex



RE: woody2.js: custom validation issue in cocoon-2.1.2 to 2.1.4

Posted by Alex Kovacs <al...@fast.fujitsu.com.au>.
Hi Tim,

I have a task to port an older demo to the new cocoon version so I will
try it in the next few days.
Alex

> -----Original Message-----
> From: Tim Larson [mailto:tim@keow.org]
> Sent: Monday, 22 March 2004 12:04 PM
> To: dev@cocoon.apache.org
> Subject: Re: woody2.js: custom validation issue in cocoon-2.1.2 to
2.1.4
>
> On Mon, Mar 22, 2004 at 10:55:34AM +1100, Alex Kovacs wrote:
> > Hi Tim,
> >
> > Do you mean the new v2 validation framework (per widget)? I only had
a
> > quick look at the v2 and liked it very much but require some porting
> > from previous version and I do not have time to try it yet.
> > Alex
>
> Yes, that is what I meant.  Actually the whole v2/flow.js.
> I was just letting you know about it as an option and checking
> with you to see if you saw any of the same issues or other
> problems in it that we should fix before too many people
> migrate to it.
>
> --Tim Larson



Re: woody2.js: custom validation issue in cocoon-2.1.2 to 2.1.4

Posted by Tim Larson <ti...@keow.org>.
On Mon, Mar 22, 2004 at 10:55:34AM +1100, Alex Kovacs wrote:
> Hi Tim,
> 
> Do you mean the new v2 validation framework (per widget)? I only had a
> quick look at the v2 and liked it very much but require some porting
> from previous version and I do not have time to try it yet. 
> Alex

Yes, that is what I meant.  Actually the whole v2/flow.js.
I was just letting you know about it as an option and checking
with you to see if you saw any of the same issues or other
problems in it that we should fix before too many people
migrate to it.

--Tim Larson

RE: woody2.js: custom validation issue in cocoon-2.1.2 to 2.1.4

Posted by Alex Kovacs <al...@fast.fujitsu.com.au>.
Hi Tim,

Do you mean the new v2 validation framework (per widget)? I only had a
quick look at the v2 and liked it very much but require some porting
from previous version and I do not have time to try it yet. 
Alex


> -----Original Message-----
> From: Tim Larson [mailto:tim@keow.org]
> Sent: Saturday, 20 March 2004 3:47 AM
> To: dev@cocoon.apache.org
> Subject: Re: woody2.js: custom validation issue in cocoon-2.1.2 to
2.1.4
> 
> On Fri, Mar 19, 2004 at 04:43:34PM +1100, Alex Kovacs wrote:
> > Tested and it behaves the same way, i.e. does not show any custom
> > validation errors until all other fields are validated correctly.
> > However, this is not the change that I was hoping for ;-).
> 
> Have you checked the v2 flowscript?  Does it do what you want?
> I think we are slowly migrating toward using it.
> 
> --Tim Larson



Re: woody2.js: custom validation issue in cocoon-2.1.2 to 2.1.4

Posted by Tim Larson <ti...@keow.org>.
On Fri, Mar 19, 2004 at 04:43:34PM +1100, Alex Kovacs wrote:
> Tested and it behaves the same way, i.e. does not show any custom
> validation errors until all other fields are validated correctly.
> However, this is not the change that I was hoping for ;-). 

Have you checked the v2 flowscript?  Does it do what you want?
I think we are slowly migrating toward using it.

--Tim Larson

Re: woody2.js: custom validation issue in cocoon-2.1.2 to 2.1.4

Posted by Sylvain Wallez <sy...@apache.org>.
Joerg Heinicke wrote:

>Sylvain Wallez <sylvain <at> apache.org> writes:
>
>  
>
>>>I have committed it this way to the forms block in CVS:
>>>
>>>if (finished) {
>>>   if (this.validator == null) {
>>>       this.isValid = this.form.isValid();
>>>   } else {
>>>       this.isValid = this.form.isValid()
>>>                      & this.validator(this.form, bizData);
>>>   }
>>>   finished = this.isValid;
>>>}
>>>
>>>Should work as well. Can you test it?
>>> 
>>>
>>>      
>>>
>>This was written that way on purpose, in order for the flow-level 
>>validation do be assured that the form was valid and not to care about 
>>it. This change means that flow-level validation has now to check if the 
>>form is valid, which may break some of the existing uses.
>>    
>>
>
>IMO it's really bad usability to present the user the validation results in
>multiple steps. I have the same problem at the moment for the
>wd:validation/wd:javascript, this is also only executed after the form itself is
>valid. If you add in the form1.xml a @required="true" to the email and make a
>duplicate entry for the firstname, you first have to fill all emails to get the
>validation on unique names running.
>  
>

I see your point. So we may change the semantics of validators and say 
that they're *always* called and should take care that they may act on 
invalid widgets.

>IMO it must be possible to get a form validated completely in one submit, not
>"fixing the last issue, submit, ... again three errors :-(".
>  
>

That totally makes sense.

>>Note that I plan to remove this feature in CForms as we can now add 
>>arbitrary validators on the Form itself.
>>    
>>
>
>"this feature" is this.validator? What exactly does "this" refer to at the
>moment? And later it will be this.form.validator or
>this.form.addValidator(validator) or something similar?
>  
>

The "this" refers to the fact that we can add a validator at the 
flowscript level. As we can add regular WidgetValidators on the Form 
(and on any widget, BTW), there's no need anymore for this flow-specific 
feature.

Sylvain

-- 
Sylvain Wallez                                  Anyware Technologies
http://www.apache.org/~sylvain           http://www.anyware-tech.com
{ XML, Java, Cocoon, OpenSource }*{ Training, Consulting, Projects }


Re: woody2.js: custom validation issue in cocoon-2.1.2 to 2.1.4

Posted by Joerg Heinicke <jo...@gmx.de>.
Sylvain Wallez <sylvain <at> apache.org> writes:

> >I have committed it this way to the forms block in CVS:
> >
> >if (finished) {
> >    if (this.validator == null) {
> >        this.isValid = this.form.isValid();
> >    } else {
> >        this.isValid = this.form.isValid()
> >                       & this.validator(this.form, bizData);
> >    }
> >    finished = this.isValid;
> >}
> >
> >Should work as well. Can you test it?
> >  
> >
> 
> This was written that way on purpose, in order for the flow-level 
> validation do be assured that the form was valid and not to care about 
> it. This change means that flow-level validation has now to check if the 
> form is valid, which may break some of the existing uses.

IMO it's really bad usability to present the user the validation results in
multiple steps. I have the same problem at the moment for the
wd:validation/wd:javascript, this is also only executed after the form itself is
valid. If you add in the form1.xml a @required="true" to the email and make a
duplicate entry for the firstname, you first have to fill all emails to get the
validation on unique names running.

IMO it must be possible to get a form validated completely in one submit, not
"fixing the last issue, submit, ... again three errors :-(".

> Note that I plan to remove this feature in CForms as we can now add 
> arbitrary validators on the Form itself.

"this feature" is this.validator? What exactly does "this" refer to at the
moment? And later it will be this.form.validator or
this.form.addValidator(validator) or something similar?

Joerg


Re: woody2.js: custom validation issue in cocoon-2.1.2 to 2.1.4

Posted by Sylvain Wallez <sy...@apache.org>.
Joerg Heinicke wrote:

>Alex Kovacs <alexk <at> fast.fujitsu.com.au> writes:
>  
>
>>            if (this.validator == null) {
>>		  //if no custom validation
>>              this.isValid = this.form.isValid();
>>            } else {
>>	          var validated = true;
>>	          
>>	          if(!this.validator(this.form, bizData))
>>	          	validated = false;
>>	          
>>	          if(!this.form.isValid())
>>	          	validated = false;
>>	          	
>>              this.isValid = validated;
>>              finished = this.isValid;
>>            }
>>    
>>
>
>I have committed it this way to the forms block in CVS:
>
>if (finished) {
>    if (this.validator == null) {
>        this.isValid = this.form.isValid();
>    } else {
>        this.isValid = this.form.isValid() & this.validator(this.form, bizData);
>    }
>    finished = this.isValid;
>}
>
>Should work as well. Can you test it?
>  
>

This was written that way on purpose, in order for the flow-level 
validation do be assured that the form was valid and not to care about 
it. This change means that flow-level validation has now to check if the 
form is valid, which may break some of the existing uses.

Note that I plan to remove this feature in CForms as we can now add 
arbitrary validators on the Form itself.

Sylvain

-- 
Sylvain Wallez                                  Anyware Technologies
http://www.apache.org/~sylvain           http://www.anyware-tech.com
{ XML, Java, Cocoon, OpenSource }*{ Training, Consulting, Projects }


Re: woody2.js: custom validation issue in cocoon-2.1.2 to 2.1.4

Posted by Joerg Heinicke <jo...@gmx.de>.
On 19.03.2004 06:43, Alex Kovacs wrote:

> Tested and it behaves the same way, i.e. does not show any custom
> validation errors until all other fields are validated correctly.
> However, this is not the change that I was hoping for ;-). 
> 
> I think the test "if (finished)" is the problem. It only allows for
> custom validation just after the form is finished. The finished variable
> comes from some lines above in woody2.js:
> 	finished = this.form.process(formContext);
> So it seems the form is validated (i.e. finished) only if the built-in
> validation is completed. And my understanding is that the form is not
> finished until there are no errors, regardless if they are coming from
> the custom validation or not. Therefore, I still think the fix above
> does not solve my issues. I my code above I've actually removed the "if
> (finished ...)" statement to make the fix working ok.
> 
> What do you think?

Ah, sorry for that. I hadn't the finished in mind and did not thought 
that you removed this first completely from your snippet. I will have a 
look on it.

Joerg

RE: woody2.js: custom validation issue in cocoon-2.1.2 to 2.1.4

Posted by Alex Kovacs <al...@fast.fujitsu.com.au>.
> Alex Kovacs <alexk <at> fast.fujitsu.com.au> writes:
> 
> >             if (this.validator == null) {
> > 		  //if no custom validation
> >               this.isValid = this.form.isValid();
> >             } else {
> > 	          var validated = true;
> >
> > 	          if(!this.validator(this.form, bizData))
> > 	          	validated = false;
> >
> > 	          if(!this.form.isValid())
> > 	          	validated = false;
> >
> >               this.isValid = validated;
> >               finished = this.isValid;
> >             }
> 
> I have committed it this way to the forms block in CVS:
> 
> if (finished) {
>     if (this.validator == null) {
>         this.isValid = this.form.isValid();
>     } else {
>         this.isValid = this.form.isValid() & this.validator(this.form,
> bizData);
>     }
>     finished = this.isValid;
> }
> 
> Should work as well. Can you test it?
> 

Tested and it behaves the same way, i.e. does not show any custom
validation errors until all other fields are validated correctly.
However, this is not the change that I was hoping for ;-). 

I think the test "if (finished)" is the problem. It only allows for
custom validation just after the form is finished. The finished variable
comes from some lines above in woody2.js:
	finished = this.form.process(formContext);
So it seems the form is validated (i.e. finished) only if the built-in
validation is completed. And my understanding is that the form is not
finished until there are no errors, regardless if they are coming from
the custom validation or not. Therefore, I still think the fix above
does not solve my issues. I my code above I've actually removed the "if
(finished ...)" statement to make the fix working ok.

What do you think?
Alex



Re: woody2.js: custom validation issue in cocoon-2.1.2 to 2.1.4

Posted by Joerg Heinicke <jo...@gmx.de>.
Alex Kovacs <alexk <at> fast.fujitsu.com.au> writes:

>             if (this.validator == null) {
> 		  //if no custom validation
>               this.isValid = this.form.isValid();
>             } else {
> 	          var validated = true;
> 	          
> 	          if(!this.validator(this.form, bizData))
> 	          	validated = false;
> 	          
> 	          if(!this.form.isValid())
> 	          	validated = false;
> 	          	
>               this.isValid = validated;
>               finished = this.isValid;
>             }

I have committed it this way to the forms block in CVS:

if (finished) {
    if (this.validator == null) {
        this.isValid = this.form.isValid();
    } else {
        this.isValid = this.form.isValid() & this.validator(this.form, bizData);
    }
    finished = this.isValid;
}

Should work as well. Can you test it?

Thanks,

Joerg