From: Alex T. <al...@tw...> - 2005-06-15 22:29:40
|
Alex Tweedly wrote: > Bryan Murdock wrote: > >> I'm writing an app that will open up a CustomDialog asking the user to >> fill in a number of TextFields. I'm trying to figure out a good >> design for validating the fields and prompting the user to try again >> if they left one blank, or entered something invalid. It looks to me >> like it can only be done after the user clicks OK and I get the result >> back. I'm having my Background create an alert dialog telling the >> user what they did wrong, and then go back and redisplay the dialog, >> which is kind OK, I guess. Any suggestions for improvement? > > You can do it in the custom dialog function. This simple example will > keep the dialog on-screen until it gets a satisfactory value for one > of the fields (or the "Cancel" button is clicked). which is true - but there's a better (and more obvious !!) way .... put in your own handler for the OK button within the dialog, validate any fields there - if they're good, do an event.skip(), if they're bad, pop up an alert (or whatever else you want) to inform the user ... from PythonCard import model, dialog class MyDialog(model.CustomDialog): def __init__(self, parent, txt=''): model.CustomDialog.__init__(self, parent) def on_btnOK_mouseClick(self, event): if self.components.TextField1.text == "Done": event.skip() else: result = dialog.alertDialog(self, 'Field 1 must be "Done"', 'title') def myDialog(parent): dlg = MyDialog(parent) result = dlg.showModal() ## result.TextField1 = dlg.components.TextField1.text ## result.TextField2 = dlg.components.TextField2.text result.texts = {} for name in ["TextField1", "TextField2"]: result.texts[name] = dlg.components[name].text dlg.destroy() return result -- Alex Tweedly http://www.tweedly.net -- No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.0.323 / Virus Database: 267.7.3/15 - Release Date: 14/06/2005 |