Created
October 1, 2012 14:18
-
-
Save ralphbean/3812049 to your computer and use it in GitHub Desktop.
Playing with tw2 form validation and the MatchValidator.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import tw2.core as twc | |
| import tw2.forms as twf | |
| class SettingsForm(twf.Form): | |
| submit = twf.SubmitButton(value='Update') | |
| action = '/update_settings' | |
| class child(twf.TableLayout): | |
| hover_help = True | |
| new_login_email = twf.TextField( | |
| help_text='Enter a new login email.', | |
| validator=twc.EmailValidator) | |
| confirm_new_email = twf.TextField( | |
| help_text='Confirm new login email address.', | |
| validator=twc.MatchValidator('new_login_email') | |
| ) | |
| new_password = twf.PasswordField( | |
| help_text='Enter new password.') | |
| confirm_new_password = twf.PasswordField( | |
| help_text='Confirm new password.', | |
| validator=twc.MatchValidator('new_password') | |
| ) | |
| current_password = twf.PasswordField( | |
| help_text='Enter current password.', | |
| validator=twc.Required) | |
| if __name__ == '__main__': | |
| # This succeeeds, since new_login_email == confirm_new_email. They are | |
| # both blank. | |
| SettingsForm.validate({ | |
| 'new_password': 'secret', | |
| 'confirm_new_password': 'secret', | |
| 'current_password': 'oldpass', | |
| }) | |
| # This fails appropriately. | |
| SettingsForm.validate({ | |
| 'new_login_email': '[email protected]', | |
| 'new_password': 'secret', | |
| 'confirm_new_password': 'secret', | |
| 'current_password': 'oldpass', | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment