omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    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

    Pythonista
    3
    4
    3567
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • echen
      echen last edited by

      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?

      Phuket2 1 Reply Last reply Reply Quote 0
      • Phuket2
        Phuket2 @echen last edited by

        @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
        
        1 Reply Last reply Reply Quote 0
        • ccc
          ccc last edited by

          https://github.com/cclauss/Pythonista_ui/blob/master/ValidatingView.py

          1 Reply Last reply Reply Quote 0
          • echen
            echen last edited by

            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?

            1 Reply Last reply Reply Quote 0
            • First post
              Last post
            Powered by NodeBB Forums | Contributors