Created
April 20, 2015 13:12
-
-
Save czbaker/6fd077a306078a9493a0 to your computer and use it in GitHub Desktop.
Form Handling
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
| Template.quickForm.events({ | |
| // Submission of Category form | |
| "submit #catForm": function(event) { | |
| // Do some form verification here | |
| var theName = event.target.catName.value; | |
| var theLimit = event.target.catLimit.value; | |
| // Thanks to: http://stackoverflow.com/questions/308122/simple-regular-expression-for-a-decimal-with-a-precision-of-2 | |
| var limitRegex = /^\d+(\.\d{1,2})?$/; | |
| if (!limitRegex.test(theLimit)) { | |
| alert("Limit must be in decimal format, such as '100.00' or '100'. Numbers only!"); | |
| // Reject the submission here. | |
| } | |
| var theCategory = { | |
| name: event.target.catName.value, | |
| limit: event.target.catLimit.value || 0, | |
| user: Meteor.userId() | |
| }; | |
| // Keep form from submitting. | |
| event.preventDefault(); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment