Skip to content

Instantly share code, notes, and snippets.

@czbaker
Created April 20, 2015 13:12
Show Gist options
  • Select an option

  • Save czbaker/6fd077a306078a9493a0 to your computer and use it in GitHub Desktop.

Select an option

Save czbaker/6fd077a306078a9493a0 to your computer and use it in GitHub Desktop.
Form Handling
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