Last active
August 29, 2015 14:25
-
-
Save chinedufn/d6facfde50d62a725554 to your computer and use it in GitHub Desktop.
Functional input validation
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
// Somewhere | |
[ | |
h('input', { | |
placeholder: 'card number', | |
oninput: function (e) {targets.handleCardNumber({number: e.srcElement.value, state: state}) | |
}), | |
h('span', state.get().cardNumberError) | |
] | |
// Elsewhere | |
function handleCardNumber (stuff) { | |
state.set('cardNumber', stuff.number) | |
state.set('cardNumberError', getNumberError(stuff.number)) | |
// maybe set an errors array as well ... | |
// maybe disable the submit button as well | |
} | |
// Another place | |
if (paymentObject.errorsArray) { | |
// not submitted | |
} | |
else { | |
submitToken( createToken(paymentObject) ) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Going to be implementing something like this later today. Structure might end up being a bit different (especially that submit flow) but you get the... gist