Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.