Changes to validation architecture

thread: 5 messages  |  last: about 5 years ago  |  started: friday, august 25, 2006, 3:44 am pdt


#1  |  Gavin Sinai (London, England) South Africa
Friday, August 25, 2006, 3:44 AM PDT

Hi Alll Qcoders

I would like to have finer control over the validation of controls.

At the moment, the validate() method of every control in a form is called automatically. If a composite control is not visible, and hence its child controls are not rendered, then the validate methods of the child controls are still called.

This can cause validation failures in controls that are not rendered.

Ideally, each composite control should be in control of whether or not each of its child control validate() methods are called or not.

A composite control could have an AutoValidateChildren property, which when set to true, would result in the present behaviour.

But when set to false, the composite control is responsible for calling validate methods in its children.

To get this working properly, minor changes in QControlBase.inc and QFormBase.inc are required.

I dont mind implementing this myself:)

Regards

Gavin

#2  |  Mike Ho (Sunnyvale, CA) United States of America Qcodo Administrator
Friday, August 25, 2006, 9:49 AM PDT

Actually, Gavin, I'll take this one step further... it's not just composite controls, but it's also QBlockControls as well (Panels and Labels) which may have child controls.

There are actually two ways that I've thought about this:

The first way is to do what you recommend -- a sort of AutoValidateChildren property.  (I like that name, btw =)

The second way is to come up with a concept of “Validation” ControlGroupings, where you could specify any number of controls to be validated in a ControlGrouping.  And where any button (or whatever control which triggers an action) can be set to validate any number of controlgroupings.

The second way obviously allows for a lot more fine-tuning/customization of what specific control(s) will get validated for specific actions... but I think it might be too much/overkill.  Also, it may be more difficult to understand.

The more I think about it, the more i think your way might be the way to go.

Yeah, if this is something you'd like to take on, go for it!  Feel free to send me any updates you have to QControlBase/QFormBase.

#3  |  Gavin Sinai (London, England) South Africa
Friday, September 1, 2006, 5:53 AM PDT

I am busy working on this.

I think the name AutoValidateChildren might be a bit misleading in the case of QForms.

For now I am calling the property ValidateAll. It can be changed with a find/replace operation.

When a qform object has ValidateAll set to true, it calls the validate method of every control in the form. It uses the present behaviour, except defining visible in a slightly different way (a control is Visible() if and only if its Visible property is true and all its ancestor controls are visible).

When ValidateAll is set to false, it calls the validate method of it's child controls only. In this case, composite controls are responsible for calling the validate methods in each of their children.

Also, when ValidateAll is set to false, a control that CausesValidation will only Cause Validation with respect to its parent control.

Keep you posted.  

Gavin.

#4  |  Mike Ho (Sunnyvale, CA) United States of America Qcodo Administrator
Friday, September 1, 2006, 8:27 AM PDT

Gavin... I think you're on the right track... BUT, you'll also need to consider the situation with QPanels, where you may have a QPanel with its own child controls, but if you're using a default QPanel, you aren't overriding the Validate() method to right your own validate handler.

Because Composite Controls and QPanels with Child Controls are so similar, I would think we would want their interaction to be the same thing... just a thought.

#5  |  Gavin Sinai (London, England) South Africa
Friday, September 1, 2006, 10:48 AM PDT

For this to work we can't use the default QPanels in the present version of qcodo. I think we have a situation where two flags are neccesary

(1) AutoValidateChildren at the control level
(2) ValidateAll at the form level.

When ValidateAll is false, AutoValidateChildren should be true, and then the desired effect will be achieved.

If a control writer wants total control over validation, s/he can use ValidateAll= false, AutoValidateChildren=false. S/he can then create the validation groups, as you have suggested, with ease.  

I am not sure whether ValidateAll is the best name, but it does the job for me.



Copyright © 2005 - 2012, Quasidea Development, LLC
This open-source framework for PHP is released under the terms of The MIT License.