Created
February 4, 2011 23:37
-
-
Save dawsontoth/812022 to your computer and use it in GitHub Desktop.
Quick Form Validation in Appcelerator Titanium (very simplistic)
This file contains 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
function validateForm() { | |
var formIsValid = true; | |
function enforceTextFieldMinLength(field, minLength) { | |
if (!field.value || field.value.length < minLength) { | |
formIsValid = false; | |
} | |
} | |
function enforceLabelHasText(label) { | |
if (!label.text) { | |
formIsValid = false; | |
} | |
} | |
// check first name | |
enforceTextFieldMinLength(tfFirstName, 5); | |
// check last name | |
enforceTextFieldMinLength(tfLastName, 5); | |
// check label connected to gender drop down | |
enforceLabelHasText(lGender); | |
if (formIsValid) { | |
alert('Form is valid!'); | |
} | |
else { | |
alert('Form is invalid...'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment