简体   繁体   English

extjs vtype在textarea上不起作用

[英]extjs vtype does not work on textarea

ok , I have a vtype for enslish and sign only that looks like this: 好的,我有一个enslish的vtype并仅签名,看起来像这样:

Ext.apply(Ext.form.VTypes, {
excel: function (v) {
    return /^.*.(xls)$/.test(v);
},
excelText: 'Must be an *.xls file',
englishOnly: function (v) {
    return /^[a-z0-9,\.\~\!\@\#\$\%\^\&\*\(\)\_\+\<\>]*$/.test(v);
},
englishOnlyTest: 'Must be English letters'

}); });

now I have a form that looks like this: 现在我有一个看起来像这样的表格:

new Ext.FormPanel({
    id: 'add-label-form',
    url: hp,
    frame: true,
    baseParams: { actionName: 'AddLable' },
    defaultType: 'textfield',
    labelWidth: 70,
    items: [{
        id: 'tbKey',
        fieldLabel: localize.key,
        allowBlank: false,
        name: 'tbKey',
        anchor: '100%'
    }, {
        id: 'tbHebrewTran',
        fieldLabel: localize.hebrew,
        allowBlank: false,
        name: 'tbHebrewTran',
        anchor: '100%'
    }, {
        id: 'tbEnglishTran',
        fieldLabel: localize.english,
        allowBlank: false,
        name: 'tbEnglishTran',
        anchor: '100%'
    }, {
        id: 'tbDescription',
        xtype: 'textarea',
        vtype:'englishOnly',
        fieldLabel: localize.description,
        allowBlank: true,
        name: 'tbDescription',
        anchor: '100%'
    }],
    buttons: [{
        text: localize.submit,
        formBind: true,
        handler: onAddLabelSubmitClick
    }, {
        text: localize.reset,
        handler: function () {
            var f = Ext.getCmp('add-label-form').getForm();
            f.reset();
        }
    }]
})

The vtype handler is called and returns false as expected but the form is still valid and no alert is displayed on the screen... why is that? 调用了vtype处理程序,并按预期返回false,但是该窗体仍然有效,并且屏幕上未显示任何警报...为什么?

Make sure to include monitorValid: true in your FormPanel config. 确保在FormPanel配置中包括monitorValid: true

Here's a comment from the API that explains the config option in more detail: 这是API的注释,其中更详细地说明了config选项:

monitorValid : Boolean monitorValid:布尔值

If true, the form monitors its valid state client-side and regularly fires the clientvalidation event passing that state. 如果为true,则表单将在客户端监视其有效状态,并定期触发传递该状态的clientvalidation事件。

When monitoring valid state, the FormPanel enables/disables any of its configured buttons which have been configured with formBind: true depending on whether the form is valid or not. 监视有效状态时,FormPanel启用/禁用已使用formBind:true配置的任何已配置按钮,具体取决于表单是否有效。 Defaults to false. 默认为false。

With this set you should see the Button enabled/disabled and a red outline around whatever field the vtype applied to. 使用此设置后,您应该看到已启用/禁用按钮,并且在vtype应用于的任何字段周围都有一个红色的轮廓。

Update: 更新:

I noticed that your text variable for englishOnly is defined as englishOnlyTest , and I think it should be defined as englishOnlyText (you spelled "test" instead of "text"). 我注意到您的englishOnly文本变量定义为englishOnlyTest ,我认为应该将其定义为englishOnlyText (您拼写为“ test”而不是“ text”)。 If I recall correctly the framework expects to see text appended to the string that you want to use for the returned text. 如果我没记错的话,框架希望看到文本附加到要用于返回文本的字符串上。 This may be why you're not seeing any red outline or popup text. 这就是为什么您看不到任何红色轮廓或弹出文本的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM