QDialogBox validation problem.

Login or register to post comments
8 replies [Last post]
Offline
Joined: 06/25/2009

Hello,

I've tried searching the Forums, Examples, and API docs, but I'm still stumped.

What I'm looking for is a way to disregard form validation on a QForm, but *only* when someone clicks 'Save' within a QDialogBox, which also has a bunch of input fields that need to be validated.

I did find that I could define a new Validate() method in my QDialogBox class, but even if I return true (so the form succeeds), the input controls "behind" the QDialogBox (on the main QForm) also do validation and fail (because nothing has been input in them yet), which means the data in the QDialogBox is not saved, and the dialog box never goes away.

Hopefully that makes sense, is there some way around this that I'm just not connecting the dots on?

Offline
Joined: 06/25/2009

Hate to bump, but any takers? I'm a bit stumped :-(

Offline
Joined: 08/12/2009

have you tried

$myDialogBoxButtonSave->CausesValidation = false;

Offline
Joined: 06/25/2009

I can't disable the validation on the dialog box since it does have fields that need validation. Additionally, the fields "behind" the QDialogBox also have validation, but only need to be validated when the main form is saved, not the QDialogBox.

alex94040's picture
Offline
Joined: 11/06/2008

Consider overriding the Form_Validate() method in the form. That's the method that gets called when the entire form is validated.

I'd do this: if you want the form to only be validated when the dialog box is NOT shown, set a flag when the dialog shows up. Check that flag in Form_Validate() before the parent validate call, and if the flag is set (i.e. the dialog is showing), do the dialog validation. Return True if the dialog validation passes.

Offline
Joined: 06/25/2009

Alex, thanks for the suggestion, however, I was not able to get it. What I ended up doing was setting Required for each of my main form controls to false on creating the QPanel, then changing them back to true on closing of the QPanel. I'm also disabling the main form 'save' button in the same manner, so they can't save the main form in a weird state (with certain things filled out 1/2 way, etc.). It works, though I think it's a bit hokey.

vakopian's picture
Offline
Joined: 04/08/2008

I don't know if this is useful for you, but you don't have to fully enable or disable the validation, you could also tell the button which controls it should validate. For example:

$myDialogBoxButtonSave->CausesValidation = array($this->txtName, $this->txtEmail);

-Vartan

Steven Warren's picture
Offline
Joined: 11/06/2008

Now that's a nifty trick Vartan. I will have to test that out, I can see many places where that would be useful.

Offline
Joined: 03/31/2008

There's also CausesValidation = QCausesValidation::SiblingsAndChildren, as covered in the validation example:
http://examples.qcu.be/assets/_core/php/examples/basic_qform/calculator_...