I have a search form (ExtJS 4.2) with a few fields:
xtype: 'fieldcontainer',
layout: 'hbox',
items: [{
xtype: 'combobox',
itemId: 'cboEmployee',
width: 400,
store: cboEmployeeStore,
cls: 'arigth',
displayField: 'FullName',
valueField: 'EmployeeId',
queryMode: 'remote',
fieldLabel: 'Employee',
editable: true,
hideTrigger: true,
queryParam: 'searchStr',
name: 'EmployeeId',
minChars: 3,
listConfig: {
loadingText: 'Searching...',
// Custom rendering template for each item
getInnerTpl: function() {
return '<b>{EmployeeNumber}</b> / {FullName}';
}
}
}, {
xtype: 'datefield',
fieldLabel: 'From',
name: 'FromDate',
format: 'd/m/Y',
submitFormat: 'Y-m-d H:i:s',
width: 180,
labelWidth: 50,
cls: 'arigth',
value: new Date()
}, {
xtype: 'datefield',
fieldLabel: 'To',
name: 'ToDate',
format: 'd/m/Y',
submitFormat: 'Y-m-d H:i:s',
width: 165,
labelWidth: 25,
cls: 'arigth',
value: new Date()
}, {
xtype: 'button',
action: 'search',
text: 'Search',
margin: '0 0 0 20'
}]
Now in my controller when my button "search" is clicked I have the following code:
var values = {};
form.items.each(function(f) {
var field = f.getName();
var value = f.getValue();
if (field == "EmployeeId" && value == "") value = 0;
values[field] = value;
});
I can't do: form.getValues()
because I will EmployeeId = ""
and EmployeeId
must be integer
.
That's why I implement the each
statement but...
I get an error when the item is fieldset type because
f.getName()
is undefined so I don't know if this is the best way to do this in order to setEmployeeId = 0
whenEmployeeId
field value is "" (empty string).