Simple form validation in Sencha Touch
I've seen several examples of form validation in Sencha Touch, but all seem overly complex for what I want to do. I don't need a model or store, as the fields in question will be handled server-side. Is there any easy way to simply check if th开发者_JAVA技巧e field in a form is populated before submitting it?
I've tried
if (myForm.getComponent('fieldset').getComponent('myField').length == 0)
{
/// Do something
}
but the condition isn't met even when the field is empty. No JS errors in the console.
You need to get the field's value first. You're probably always failing the condition, because .length
is being evaluated against that component and not its text, so if the component is defined, its length will always be greater than zero.
Try this:
if (myForm.getComponent('fieldset').getComponent('myField').getValue().length == 0)
{
/// Do something
}
精彩评论