开发者

Simple form validation in Sencha Touch

开发者 https://www.devze.com 2023-04-01 21:11 出处:网络
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

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
}
0

精彩评论

暂无评论...
验证码 换一张
取 消