| View previous topic :: View next topic |
| Author |
Message |
ynaras Power User


Joined: 01 Nov 2004 Posts: 78 Location: Waltham, MA
|
Posted: Mon May 16, 2005 7:38 am Post subject: Validate data in a dialog |
|
|
Hello OO Gurus,
I have created a dialog called EditLaborRowTask. I have created a textbox in this dialog called txtName. I also have an OK and a Cancel button on this dialog. I have the following code for validating the data in the dialog:
| Code: |
DialogLibraries.LoadLibrary("Standard")
dlgEditLaborRowTask = CreateUnoDialog(DialogLibraries.Standard.EditLaborRowTask)
dlgEditLaborRowTask.setVisible( True )
If dlgEditLaborRowTask.Execute() = 1 Then 'OK Clicked
If Not dlgEditLaborRowTask.getControl( "txtName" ).Text = "" Then
Msgbox( "Please enter a valid name." )
End If
End if
|
Now, if I leave out the name and click OK, I get the message "Please enter a valid name". However the dialog box closes down by the time I get this message. Is there a way to pop this message box and retain the dialog, so that the user can key in a name?
Thanks,
Yogesh. |
|
| Back to top |
|
 |
SergeM Super User

Joined: 09 Sep 2003 Posts: 3211 Location: Troyes France
|
|
| Back to top |
|
 |
DannyB Moderator


Joined: 02 Apr 2003 Posts: 3991 Location: Lawrence, Kansas, USA
|
Posted: Mon May 16, 2005 8:53 am Post subject: |
|
|
Let me try to same the same thing as SergeM, but more clearly.
Create a new subroutine.
The OK button must have its "when initiating" event bound to the new subroutine.
| Code: | Sub btnOK_clicked( oEvent )
End Sub
|
Now when OK is clicked, the sub btnOK_clicked() is called.
Inside that sub, do your validation test.
| Code: | Sub btnOK_clicked( oEvent )
If Not dlgEditLaborRowTask.getControl( "txtName" ).Text = "" Then
Msgbox( "Please enter a valid name." )
Else
dlgEditLaborRowTask.endExecute() ' this makes the dialog go away
End If
End Sub
|
In your main sub...
| Code: | DialogLibraries.LoadLibrary("Standard")
dlgEditLaborRowTask = CreateUnoDialog(DialogLibraries.Standard.EditLaborRowTask)
dlgEditLaborRowTask.Execute()
' Note execution does not reach this point, until someone calls endExecute to stop the modal dialog box.
MsgBox "This message does not display until the dialog is gone."
|
you execute the dialog box. _________________ Want to make OOo Drawings like the colored flower design to the left? |
|
| Back to top |
|
 |
ynaras Power User


Joined: 01 Nov 2004 Posts: 78 Location: Waltham, MA
|
Posted: Mon May 16, 2005 9:34 am Post subject: |
|
|
Serge, great idea, I would however like to give Danny's solution a try first. I want the user to tab between the varios form controls. I do not want to add validation at the control level as too many validation messages will annoy the users. Danny, I like your idea, that solution will work very well for me. I will give that a shot first.
Thank you guys,
Yogesh. |
|
| Back to top |
|
 |
SergeM Super User

Joined: 09 Sep 2003 Posts: 3211 Location: Troyes France
|
|
| Back to top |
|
 |
|