OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Validate data in a dialog

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
ynaras
Power User
Power User


Joined: 01 Nov 2004
Posts: 78
Location: Waltham, MA

PostPosted: Mon May 16, 2005 7:38 am    Post subject: Validate data in a dialog Reply with quote

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
View user's profile Send private message Visit poster's website
SergeM
Super User
Super User


Joined: 09 Sep 2003
Posts: 3211
Location: Troyes France

PostPosted: Mon May 16, 2005 7:54 am    Post subject: Reply with quote

Code:
If dlgEditLaborRowTask.Execute() = 1 Then 'OK Clicked

When the if is tested that means that the execute is terminated that means the dialog box is finished.
You can associate a sub to the button and test in this sub if text is valid or not.
_________________
Linux & Windows OOo3.0
UNO & C++ : WIKI
http://wiki.services.openoffice.org/wiki/Using_Cpp_with_the_OOo_SDK
In French
http://wiki.services.openoffice.org/wiki/Documentation/FR/Cpp_Guide
Back to top
View user's profile Send private message Visit poster's website
DannyB
Moderator
Moderator


Joined: 02 Apr 2003
Posts: 3991
Location: Lawrence, Kansas, USA

PostPosted: Mon May 16, 2005 8:53 am    Post subject: Reply with quote

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
View user's profile Send private message
ynaras
Power User
Power User


Joined: 01 Nov 2004
Posts: 78
Location: Waltham, MA

PostPosted: Mon May 16, 2005 9:34 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
SergeM
Super User
Super User


Joined: 09 Sep 2003
Posts: 3211
Location: Troyes France

PostPosted: Tue May 17, 2005 9:25 am    Post subject: Reply with quote

Thank you ynaras but I find DannyB's explanations more complete and with a gift : examples of code.
_________________
Linux & Windows OOo3.0
UNO & C++ : WIKI
http://wiki.services.openoffice.org/wiki/Using_Cpp_with_the_OOo_SDK
In French
http://wiki.services.openoffice.org/wiki/Documentation/FR/Cpp_Guide
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group