Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
textfield validation example
-
reading through the doc, I understand that I can use delegate object to to implement the functions textField_did_change to implement validation. However, I cannot find any concrete example on this. I suppose I can test for the length!=0 and issur an alrt box, but do I need to raise any exception or call a built in to stop the processing when it failed such test? Any pointers?
-
@echen, the delegate callbacks are below.
If you test the replacement param in textfield_should_change(), you can return True or False. Example, if you don't want spaces, you can check and decide to accept the replacement or not by returning True or False. I haven't done much with TextField before. But as far as I can understand you can't count on you will get 1 char at a time. I think the range is there because if the user hits a keyboard suggestion, I think you get all the text at once. I am not 100% sure you can test.class MyTextFieldDelegate (object): def textfield_should_begin_editing(self, textfield): return True def textfield_did_begin_editing(self, textfield): pass def textfield_did_end_editing(self, textfield): pass def textfield_should_return(self, textfield): textfield.end_editing() return True def textfield_should_change(self, textfield, range, replacement): return True def textfield_did_change(self, textfield): pass
-
-
thanks for the replies, I think I understood it better now. One more question, how I keep the input focus to a field if it fails a validation, but still allow the user to cancel or click the X button to close the view?