1

コンボボックスとテキストフィールドがあります。コンボボックスから何かが選択された場合、「値を入力してください」という警告通知をテキストフィールドに追加しようとしています。ただし、コンボボックスから「3」が選択されている場合にのみ、テキストフィールドに警告を表示したい

それを行う方法はありますか?その方法がわかりません。

これが私のコンボボックスとテキストフィールドのコードです:

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

2 に答える 2

2

もちろん、リスナーはコンボに参加している必要があります。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、エラー メッセージの表示方法を構成します (更新されたコード例を参照してください)。

于 2013-09-18T19:10:42.380 に答える
1

extjs では、これがリスナーを追加する方法でありon change、この場合に役立ちます。サンプル:

              {
                    xtype:'textfield',
                    fieldLabel: 'Mile',
                    id: 'mile',
                    width: 125,
                    name: 'myMiles'
                    listeners: {
                         'change': function() {
                          console.log('you changed the text of this input field');
                          var value = Ext.getCmp('mile').getValues().myMiles;
                          if(value == 3)
                          {
                            alert('You selected 3');
                          }
                        }
                    }
              }
于 2013-09-18T16:42:04.603 に答える