javascript - Adding a listener to create a warning message to a textfield - Stack Overflow

I have a bo box and a textfield. I am trying to Add a warning notifcation to the textfield stating 

I have a bo box and a textfield. I am trying to Add a warning notifcation to the textfield stating 'please enter value' if something is selected from the bo box. However, I only want the warning to display on the textfield if '3' is selected from the bo box

Is there any way that I could do that? I am not sure how to do that.

Here is the code for my bobox and textfield:

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

I have a bo box and a textfield. I am trying to Add a warning notifcation to the textfield stating 'please enter value' if something is selected from the bo box. However, I only want the warning to display on the textfield if '3' is selected from the bo box

Is there any way that I could do that? I am not sure how to do that.

Here is the code for my bobox and textfield:

{
                            xtype:'bo',
                            store: ['1','2','3'],
                            triggerAction: 'all',
                            fieldLabel: 'Area',
                            id: 'dcArea',
                            width: 125,
                        },{
                            xtype:'textfield',
                            fieldLabel: 'Mile',
                            id: 'mile',
                            width: 125,
                        }
Share Improve this question asked Sep 18, 2013 at 16:25 user1676428user1676428 6711 gold badge7 silver badges13 bronze badges 1
  • I don't usually work with extJS, so I'd suggest binding an event handler / listener to your textfield for the change event. Then check if that bobox holds the value 3. If so, display your warning. Maybe there's an easier solution with extJS, but idk. – Kiruse Commented Sep 18, 2013 at 16:28
Add a ment  | 

2 Answers 2

Reset to default 2

The listener needs to be on the bo, of course. Use msgTarget to customize how the error message is displayed.

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

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

    listeners: {
        change: function(bo, value) {
            // use ponent 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
}

Edit Use the msgTarget property of the bo box to configure how the error message is displayed (see the updated code example).

In extjs this is the way to add listeners, on change will be helpful in this case. Sample:

              {
                    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');
                          }
                        }
                    }
              }

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745626548a4636843.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信