gpt4 book ai didi

javascript - 添加监听器以向文本字段创建警告消息

转载 作者:行者123 更新时间:2023-11-30 12:56:36 24 4
gpt4 key购买 nike

我有一个组合框和一个文本框。如果从组合框中选择了某些内容,我正在尝试向文本字段添加警告通知,说明“请输入值”。但是,如果从组合框中选择“3”,我只希望警告显示在文本字段上

有什么办法可以做到吗?我不确定该怎么做。

这是我的组合框和文本字段的代码:

{
xtype:'combo',
store: ['1','2','3'],
triggerAction: 'all',
fieldLabel: 'Area',
id: 'dcArea',
width: 125,
},{
xtype:'textfield',
fieldLabel: 'Mile',
id: 'mile',
width: 125,
}

最佳答案

当然,听众需要在组合中。使用 msgTarget自定义错误消息的显示方式。

{
xtype:'combo',
store: ['1','2','3'],
triggerAction: 'all',
fieldLabel: 'Area',
// bad practice
// id: 'dcArea',
width: 150,

// <EDIT>
msgTarget: 'under',
// </EDIT>

listeners: {
change: function(combo, value) {
// use component query to retrieve the other field
var textfield = this.up('form').down('#mile');
if (value === '3') {
textfield.markInvalid("Please enter value");
} else {
textfield.clearInvalid();
}
}
}
},{
xtype:'textfield',
fieldLabel: 'Mile',
itemId: 'mile',
width: 150
}

编辑 使用 msgTarget组合框的属性来配置错误消息的显示方式(请参阅更新的代码示例)。

关于javascript - 添加监听器以向文本字段创建警告消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18877477/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com