PDA

View Full Version : Set maxValue in based on another fields value



m.tzagkarakis
16 Oct 2015, 5:33 AM
let's say we have a Ext.grid.Panel with columns:



{
text : 'Request Limit Notification',
dataIndex : 'requestlimitnotifier',
xtype: 'numbercolumn',
format: '0',
editor :
{
xtype: 'numberfield',
minValue: 0,
vtype:'maxNotifierValue',
valueLessThanField: 'clientrequestlimit'
}
},
{
text : 'Request Limit',
dataIndex : 'requestlimit',
xtype: 'numbercolumn',
format: '0',
itemId: 'clientrequestlimit',
editor :
{
xtype: 'numberfield',
minValue: 0,
allowBlank : false
}
}




The panel has a store which properly loads the values from the server (json). Now what I want is to have a validation so that request limit notifier max Value is less or equal to request limit value.


I tried to do this via a vtype like that:



maxNotifierValue: function(val, field){
if (val < 0){
return false;
}
if (field.valueLessThanField){
var maxValueField = ((Ext.ComponentQuery.query('#' + field.valueLessThanField))[0]).getEditor();
field.setMaxValue(maxValueField.getValue());
}
return true;
}


the problem with the above code is that maxValueField.getValue() is null despite the fact that the request limit field has a value or at least I can see a value on the panel and on the store.

I do not what else to try. The request limit field is not editable (I disabled it with disabling the CellEditor for this column). Also the request limit can be changed by changing values of other columns (not described here) of the panel but also it can be changed by changing other values from other tabs of my application or it simply can be changed from the server.
Any suggestions?

joel.watson
16 Oct 2015, 7:37 AM
Hi--

Your component query is returning the grid column, not the field itself. I'd try using the validateEdit event of the CellEditing plugin. You could examine the other values in the record and determine whether or not the field is valid.

http://docs.sencha.com/extjs/4.2.4/#!/api/Ext.grid.plugin.CellEditing-event-validateedit

Thanks!
Joel