admin管理员组文章数量:1302419
How can I add a change event to all 'text fields' of a form inside of a window? First I create a window with a form. All fields are initialized with a value of 0. I would like to detect the user input (maybe with dirtychange), and if the is greater than 1 then change the background color of the textField.
This is my code at the moment:
Ext.define('WPT.view.HoursPerMonthWindow', {
extend: 'Ext.window.Window',
alias : 'widget.hourspermonthwindow',
title : 'Hours per Months',
layout: 'fit',
autoShow: true,
initComponent: function() {
this.items = [
{
xtype: 'form',
items: [
{
xtype: 'textfield',
name : 'january',
itemId: 'january',
fieldLabel: 'January'
},
{
xtype: 'textfield',
name : 'february',
itemId: 'february',
fieldLabel: 'February'
}
,
{
xtype: 'textfield',
name : 'march',
itemId: 'march',
fieldLabel: 'March'
},
{
xtype: 'textfield',
name : 'april',
itemId: 'april',
fieldLabel: 'April'
},
{
xtype: 'textfield',
name : 'may',
itemId: 'may',
fieldLabel: 'May'
},
{
xtype: 'textfield',
name : 'june',
itemId: 'june',
fieldLabel: 'June'
},
{
xtype: 'textfield',
name : 'july',
itemId: 'july',
fieldLabel: 'July'
},
{
xtype: 'textfield',
name : 'august',
itemId: 'august',
fieldLabel: 'August'
},
{
xtype: 'textfield',
name : 'september',
itemId: 'september',
fieldLabel: 'September'
},
{
xtype: 'textfield',
name : 'october',
itemId: 'october',
fieldLabel: 'October'
},
{
xtype: 'textfield',
name : 'november',
itemId: 'november',
fieldLabel: 'November'
},
{
xtype: 'textfield',
name : 'december',
itemId: 'december',
fieldLabel: 'December'
}
]
}
];
this.buttons = [
{
text: 'Save',
action: 'save'
},
{
text: 'Cancel',
scope: this,
handler: this.close
}
];
this.callParent(arguments);
}
})
Have you any tips for this issue? Thx for your help Manel
How can I add a change event to all 'text fields' of a form inside of a window? First I create a window with a form. All fields are initialized with a value of 0. I would like to detect the user input (maybe with dirtychange), and if the is greater than 1 then change the background color of the textField.
This is my code at the moment:
Ext.define('WPT.view.HoursPerMonthWindow', {
extend: 'Ext.window.Window',
alias : 'widget.hourspermonthwindow',
title : 'Hours per Months',
layout: 'fit',
autoShow: true,
initComponent: function() {
this.items = [
{
xtype: 'form',
items: [
{
xtype: 'textfield',
name : 'january',
itemId: 'january',
fieldLabel: 'January'
},
{
xtype: 'textfield',
name : 'february',
itemId: 'february',
fieldLabel: 'February'
}
,
{
xtype: 'textfield',
name : 'march',
itemId: 'march',
fieldLabel: 'March'
},
{
xtype: 'textfield',
name : 'april',
itemId: 'april',
fieldLabel: 'April'
},
{
xtype: 'textfield',
name : 'may',
itemId: 'may',
fieldLabel: 'May'
},
{
xtype: 'textfield',
name : 'june',
itemId: 'june',
fieldLabel: 'June'
},
{
xtype: 'textfield',
name : 'july',
itemId: 'july',
fieldLabel: 'July'
},
{
xtype: 'textfield',
name : 'august',
itemId: 'august',
fieldLabel: 'August'
},
{
xtype: 'textfield',
name : 'september',
itemId: 'september',
fieldLabel: 'September'
},
{
xtype: 'textfield',
name : 'october',
itemId: 'october',
fieldLabel: 'October'
},
{
xtype: 'textfield',
name : 'november',
itemId: 'november',
fieldLabel: 'November'
},
{
xtype: 'textfield',
name : 'december',
itemId: 'december',
fieldLabel: 'December'
}
]
}
];
this.buttons = [
{
text: 'Save',
action: 'save'
},
{
text: 'Cancel',
scope: this,
handler: this.close
}
];
this.callParent(arguments);
}
})
Have you any tips for this issue? Thx for your help Manel
Share Improve this question asked Aug 31, 2012 at 12:29 user1638045user1638045 551 gold badge1 silver badge8 bronze badges 1- what do those textfields render as in the HTML? you could just attach the handlers through javascript if extjs doesn't provide a simple way. – jbabey Commented Aug 31, 2012 at 12:45
3 Answers
Reset to default 2Extjs offers a very simple way of adding listeners, especially the extjs 4 mvc architecture. You should add the listeners to the controller of the view
Ext.define('App.controller.SomeController', {
extend:'Ext.app.Controller',
init:function () {
this.control({
'hourspermonthwindow > form > textfield':{
change: this.handleOnChange
}
});
},
handleOnChange:function(textfield,newValue,oldValue){
//your code here
}
});
Define a new ponent that extends textfield
and add the listener in there, and then use that in your form.
Just a simple change
listener should work.
Then add a css class with the color, or if you need different colors for each row, then set it through code and use a custom color
var you pass in to your new ponent
Instead of {xtype : 'textfield' ... }
fields I have new Ext.form.TextField and I try this and work perfectly
new Ext.form.TextField({enableKeyEvents: true ,
listeners : {
change : function (f, e){
action_form_update_brdoutput(null, frmBRDOutput.getForm().getValues());
}
}
})
Extjs provides you listeners so you may overload them.
本文标签: javascriptHow to add a onChange method to all fields (textField) in a ExtJS 4 formStack Overflow
版权声明:本文标题:javascript - How to add a onChange method to all fields (textField) in a ExtJS 4 form - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741671559a2391633.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论