Skip to content

Instantly share code, notes, and snippets.

@dawsontoth
Created February 4, 2011 23:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dawsontoth/812022 to your computer and use it in GitHub Desktop.
Save dawsontoth/812022 to your computer and use it in GitHub Desktop.
Quick Form Validation in Appcelerator Titanium (very simplistic)
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