Chained combobox shows valuefield instead of displayfield when changing parent cb - extjs

How to reset chained combobox in my example the extjs way?
Consider this two comboboxes:
{
xtype: 'combo',
bind:{
store: '{contacts}'
},
reference: 'contactsCombo',
displayField: 'name',
name: 'contact',
typeAhead: false,
editable: false,
fieldLabel: 'Contact',
emptyText: 'Select a contact...',
anchor: '95%',
listeners: {
change: 'onSelectChange'
},
},
{
xtype: 'combo',
name: 'phone',
reference: 'phonesCombo',
fieldLabel: 'Phone',
displayField: 'number',
valueField:'id',
hiddenName: 'id',
emptyText: 'Select a phone...',
bind: {
store: '{contactsCombo.selection.phoneNumbers}'
},
anchor: '95%'
}
And corresponding models defines:
Ext.define('AppsBoard.model.Contact', {
extend: 'Ext.data.Model',
fields: [
'id', 'name'
],
});
Ext.define('AppsBoard.model.ViewModel', {
extend: 'Ext.app.ViewModel',
alias: 'viewmodel.related',
stores: {
contacts: {
model: 'AppsBoard.model.Contact',
autoLoad: true,
proxy: {
type: 'ajax',
url: 'contacts.json',
reader: {
type: 'json',
rootProperty: 'data'
}
}
}
}
});
Ext.define('AppsBoard.model.PhoneNumber', {
extend: 'Ext.data.Model',
fields: [
'id',
{
name: 'contact_id',
type: 'int',
reference: {
type: 'AppsBoard.model.Contact',
inverse: {
role: 'phoneNumbers'
}
}
},
'number'
],
proxy: {
type: 'MyProxy',
reader: {
type: 'json'
}
}
});
Ext.define('AppTest.store.MyProxy', {
extend: 'Ext.data.proxy.Proxy',
alias: 'proxy.MyProxy',
read: function (operation) {
var resultSet = {
1: [{
"id": 1,
"contact_id": 1,
"number": "6045551212"
},
{
"id": 2,
"contact_id": 1,
"number": "8009996541"
}],
2: [
{
"id": 3,
"contact_id": 2,
"number": "1232131233"
}
]
};
operation.setResultSet(this.getReader().read(resultSet[operation.getFilters()[0].getValue()]));
operation.setSuccessful(true);
},
erase: function (operation) {
console.log(operation);
}
});
My problem is when i switching my parent Combobox, it's associated child combobox shows valueField instead of displayField.
https://fiddle.sencha.com/#fiddle/vtg

you can see in your fiddle it's not use valueField but it's keep the value.
Since the store has been change the value is now not associated to anything in the new store, therefore you keep seen only the value.
you can clean the box by setting the forceSelection
{
xtype: 'combo',
name: 'phone',
reference: 'phonesCombo',
fieldLabel: 'Phone',
displayField: 'number',
valueField:'id',
hiddenName: 'id',
emptyText: 'Select a phone...',
forceSelection: true,
bind: {
store: '{contactsCombo.selection.phoneNumbers}'
},
anchor: '95%'
}
as long as you know there won't be a duplicates IDs

Related

ExtJS Assigning value to the hidden field

I have the below combobox set to put some records through API call and then display on the page. I need to submit 2 values when user clicks submit, 1) gmiExchangeCode and 2) gmiFuturesCode. The first value works through this form's field, the gmiFuturesCode doesn't work on updating the hidden form field.
}, {
xtype: 'combo',
autoLoad: true,
hideTrigger: true,
fieldLabel: 'Product',
displayField: 'gmiDescription',
valueField: 'gmiExchangeCode',
submitValue: true,
name: 'exchange',
queryMode: 'remote',
queryParam: 'entry',
typeAhead: true,
minChar: 2,
tpl: new Ext.XTemplate('<tpl for="."><div class="x-boundlist-item" style="border-bottom:1px solid #757575;">{gmiExchangeCode} - {lisaMarket} - {gmiFuturesCode} - {gmiDescription}</div></tpl>'),
store: {
fields: ['text', 'value'],
proxy: {
type: 'ajax',
url: 'API',
reader: {
type: 'json'
}
}
},
listeners: {
select: function (combo, record, index) {
hidden.setValue(record.get('gmiFuturesCode'));
}
}
}, {
xtype: 'hidden',
id: 'futures',
name: 'futures'
}, {
There is nothing called "hidden.setValue()" you have to get the object using the query selector or Ext.getCmp('ObjectID')
Here is a working Example Fiddle
Ext.create('Ext.form.Panel', {
title: 'test',
width: 400,
height: 300,
renderTo: Ext.getBody(),
items: [{
xtype: 'combobox',
reference: 'states',
publishes: 'value',
fieldLabel: 'Select State',
displayField: 'displayField',
anchor: '-15',
store: {
fields: ['valueField', 'displayField'],
data: [
['1', 'MyDisplayValueFor1'],
['2', 'MyDisplayValueFor2'],
['3', 'MyDisplayValueFor3']
]
},
minChars: 0,
queryMode: 'local',
typeAhead: true,
listeners: {
select: function (combo, record, index) {
console.log(record.get('displayField'));
Ext.getCmp('futures').setValue(record.get('displayField'));
Ext.Msg.alert('Alert', 'The hidden Field value from the getter is : ' + Ext.getCmp('futures').getValue());
}
}
}, {
xtype: 'hidden',
id: 'futures',
name: 'futures'
}]
})
Try this
Ext.getCmp('futures').setValue(record.get('gmiFuturesCode'));

extjs form,combo and hiddenname

Have this code.
Ext.define('App.v2.model.Things', {
extend: 'App.v2.model.Base'
,fields: [{
name: 'C'
,type:'int'
},{
name:'NAME'
,type:'string'
},{
name:'SHORT_NAME'
,type:'string'
}]
,proxy:{
url:'/data/data1.php'
,reader : {
rootProperty: 'data'
},
extraParams: {
limit: 1000
}
},
idProperty: 'C'
});
model for document
Ext.define('App.v2.model.ThingsList', {
extend: 'App.v2.model.Base'
,fields: [{
name: 'C'
,type:'int'
},
{
name: 'THING_ID',
type:'int'
},
{
name: 'ZE',
type:'int'
},
{
name: 'HS',
type:'int'
},
{
name: 'THING_NAME',
type:'string'
},]
,proxy:{
url:'/data/thingsList.php'
,reader : {
rootProperty: 'data'
}
},
idProperty: 'C'
});
Form config
items: [{
xtype: 'form',
bodyStyle: 'border:none',
defaultType: 'textfield',
layout: 'fit',
maindata: [{
xtype: 'panel',
//layout: 'vbox',
layout: 'vbox',
id: 'ThingsForm',
items: [{
xtype: 'textfield',
fieldLabel: 'ЗЕ',
name: 'ZE',
width: 400,
allowBlank: false
},
{
xtype: 'textfield',
fieldLabel: 'HS',
name: 'HS',
width: 400,
allowBlank: false
},
{
xtype: 'combo',
fieldLabel: 'Thing',
name: 'THING_ID',
hiddenName: 'THING_NAME',
valueField: 'C',
displayField: 'SHORT_NAME',
store : {
model:'App.v2.model.Things',
autoLoad: true,
}
}
//]
]
}]
}]
load data to form
row = grid.store.getAt(this.conf.grid.getSelectionModel().getCurrentPosition().rowIdx);
form = this.down('form').getForm();
form.loadRecord(row);
all good. Form show values
after change of form try to update record
var record = form.getRecord(); // see old values of THING_ID and THING_NAME
record.set(form.getValues()); // see new value of THING_ID and OLD value of THING_NAME
How update THING_NAME to NEW value (TEXT) selected on COMBO in record?
only like describe there?
ExtJS 5 combobox - submitting both value and text

Data binding associations in ExtJS admin template

I'm unsuccessful in getting binding associations working in the admin dashboard template (with the desired behavior of selecting a record from a combobox and pulling up associated records in a grid).
My main viewModel is defined as:
Ext.define('Admin.view.main.MainModel', {
extend: 'Ext.app.ViewModel',
alias: 'viewmodel.main',
stores: {
patients: {
model: 'md_registry.model.Patient',
autoLoad: true
}
}
});
I added a leaf node to Pages in NavigationTree.js:
{
text: 'Pages',
iconCls: 'x-fa fa-leanpub',
expanded: false,
selectable: false,
//routeId: 'pages-parent',
//id: 'pages-parent',
children: [
{
text: 'Proc',
iconCls: 'x-fa fa-send',
rowCls: 'nav-tree-badge nav-tree-badge-hot',
viewType: 'procedure',
leaf: true
}]
}
With the procedure view being:
Ext.define('Admin.view.pages.Procedure', {
extend: 'Ext.panel.Panel',
xtype: 'procedure',
requires: [
'Ext.panel.Panel',
'Admin.model.Patient',
'Admin.model.Procedure'
//'Admin.model.Diagnosis'
],
anchor : '100% -1',
referenceHolder: true,
width: 1000,
height: 1000,
referenceHolder: true,
layout: {
type: 'hbox',
align: 'stretch'
},
viewModel: 'main',
session: {},
items: [
// https://www.sencha.com/forum/showthread.php?299301-Bind-combobox-displayField-value-to-displayfield
{
xtype: 'fieldset',
layout: 'anchor',
items: [{
xtype: 'combobox',
listeners : {
select : function() {
console.log(arguments)
console.log(arguments[1].data.birth_date)
console.log(arguments[1].data.first_name)
console.log(arguments[1].data.last_name)
console.log(arguments[1].data.sex)
}
},
bind: {
store: '{patients}'
},
reference: 'patientCombo',
publishes: 'id',
fieldLabel: 'Patient Search',
displayField: 'mrn',
//anchor: '-',
// We're forcing the query to run every time by setting minChars to 0
// (default is 4)
minChars: 2,
queryParam: '0',
queryMode: 'local',
typeAhead: true,
// https://www.sencha.com/forum/showthread.php?156505-Local-combobox-with-any-match-filter
doQuery: function(queryString, forceAll) {
this.expand();
this.store.clearFilter(!forceAll);
if (!forceAll) {
this.store.filter(this.displayField, new RegExp(Ext.String.escapeRegex(queryString), 'i'));
}
}
}, {
// https://www.sencha.com/forum/showthread.php?299301-Bind-combobox-displayField-value-to-displayfield
xtype: 'displayfield',
fieldLabel: 'Selected Patient',
bind: {
html: '<p>Name: <b>{patientCombo.selection.first_name}, ' +
'{patientCombo.selection.last_name} </b></p>' +
'<p>Sex: {patientCombo.selection.sex}</p>' +
'<p>Birthdate: {patientCombo.selection.birth_date}</p>'
}
}]
},
{
title: 'Procedures',
xtype: 'grid',
bind: '{patientCombo.selection.procedures}',
flex: 1,
margin: '0 0 0 10',
columns: [{
text: 'Procedure Date', dataIndex: 'proc_date', flex: 1
}, {
text: 'Procedure', dataIndex: 'proc_name', flex: 1
}],
plugins: [{
ptype: 'rowexpander',
rowBodyTpl : new Ext.XTemplate(
'<p><b>Proc Name Orig:</b> {proc_name_orig}</p>',
'<p><b>Proc Code:</b> {proc_code}</p>',
'<p><b>Proc Code Type:</b> {proc_code_type}</p>')
}],
viewConfig: {
emptyText: 'No procedures',
deferEmptyText: false
}
}]
});
My Patient and Procedure models are simply:
Ext.define('Admin.model.Procedure', {
extend: 'Ext.data.Model',
idProperty: 'id',
fields: [
//{ name: 'id', type: 'string' },
{ name: 'proc_code', type: 'string' },
{ name: 'proc_name', type: 'string' },
{ name: 'proc_code_type', type: 'string' },
{ name: 'proc_name_orig', type: 'string' },
{ name: 'proc_date', type: 'date', format: 'Y-m-d' },
{
name: 'patient_id',
type: 'string',
reference: {
parent: 'Admin.model.Patient',
//type: 'md_registry.model.Patient',
inverse: 'procedures',
autoLoad: false
}
}
],
proxy: {
type: 'rest',
url: 'http://127.0.0.1:5000/procedureview/api/read',
reader: {
type: 'json',
rootProperty: ''
}
}
});
and
Ext.define('Admin.model.Patient', {
extend: 'Ext.data.Model',
requires: [
'Ext.data.proxy.Rest'
],
fields: [
{ name: 'id', type: 'string' },
{ name: 'mrn', type: 'string' },
{ name: 'birth_date', type: 'date', format: 'Y-m-d' },
{ name: 'sex', type: 'string' },
{ name: 'first_name', type: 'string' },
{ name: 'last_name', type: 'string' }
],
proxy: {
type: 'ajax',
url: 'http://127.0.0.1:5000/patientview/api/read',
reader: {
type: 'json',
rootProperty: ''
}
}
});
respectively.
The data for my Patients store are getting loaded into the combobox just fine, but when I select an item from the combo list it is not firing off the call to grab the associated procedures data (see image: .
However, the binding associations work as expected with Side Navigation Tabs (see image: , and show up within the object prototype chain, as expected... see
(whereas for the admin dashboard, the associations are empty).
I cannot for the life of me get these working in the Admin Dashboard. I noticed a tool called the bind inspector, but I am running the GPL version of the SDK, so I do not have access to this. Beyond this, I cannot figure out a way to debug why the binding association is not working in the admin dashboard, but otherwise works perfectly well in Side Navigation Tabs.
I would set up a Fiddle, but I have no idea how to do it using the Admin Template.
I just figured it out. It was a namespace issue.
My reference in the procedure model should be:
reference: {
parent: 'Patient',
inverse: 'procedures',
autoLoad: false
}
Voila, all the associated data get loaded as expected!

Combobox inside grid doesn't show data after rendering

I have a grid that has combobox on one column. Data loads fine on the grid. But when I double click on one row to enable edit, the combobox doesn't show the data. (Please see the screenshot below) The highlighted part should show '1st Label'. But when I start to edit, it shows up like in the 2nd row with '2nd Label'.
I tried my code on 4.1 and it works fine. It seems 4.2.2 doesn't like combobox inside grid. Any help is really appreciated
This is my sample code. Please try it on Sencha's Code Editor to see both on 4.2.2 and 4.1.0
Ext.define('GridModel', {
extend: 'Ext.data.Model',
fields: [{
name: 'Id',
type: 'int'
}, {
name: 'Value',
type: 'int'
}]
});
Ext.define('ComboModel', {
extend: 'Ext.data.Model',
fields: [{
name: 'ComboId',
type: 'int'
}, {
name: 'Label',
type: 'string'
}],
idProperty: 'Order'
});
Ext.create('Ext.data.Store', {
storeId: 'comboStore',
model: 'ComboModel',
data: [{
ComboId: 1,
Label: '1st Label'
}, {
ComboId: 2,
Label: '2nd Label'
}]
});
Ext.create('Ext.data.Store', {
storeId: 'gridStore',
model: 'GridModel',
data: [{
Id: 1,
Value: 1
}, {
Id: 2,
Value: 2
}, {
Id: 3,
Value: 1
}, {
Id: 4,
Value: 2
}]
});
Ext.create('Ext.grid.Panel', {
width: 400,
height: 200,
renderTo: 'ct',
plugins: [
Ext.create('Ext.grid.plugin.RowEditing', {
clicksToEdit: 2,
listeners: {
edit: function(editor, e) {
console.log(gridStore.getModifiedRecords());
}
}
})
],
store: Ext.data.StoreManager.lookup('gridStore'),
forceFit: true,
columns: [{
dataIndex: 'Id',
header: 'ID'
}, {
dataIndex: 'Value',
header: 'Label',
editor: {
xtype: 'combobox',
displayField: 'Label',
valueField: 'ComboId',
queryMode: 'local',
store: Ext.data.StoreManager.lookup('comboStore'),
allowBlank: true
},
renderer: function(value) {
var rec = comboStore.getById(value);
return rec ? rec.get('Label') : value;
}
}],
renderTo: Ext.getBody()
});

Load form from combo

I'm trying to load a form from a record selected in a combo.
The store is loaded properly and the combo is populated, but, when I select a value from combo, form fields remain empty.
Any help will be appreciated.
This is the code:
Model:
Ext.define('AA.model.proc.Process', {
extend: 'Ext.data.Model',
fields: [
{ name: 'name', type: 'string' },
{ name: 'owner', type: 'string' },
{ name: 'mail_dest', type: 'string' }
],
proxy: {
type: 'rest',
url : 'data/camp.json',
reader: {
type: 'json',
root: 'camp',
totalProperty: 'count'
}
}
});
Store:
Ext.define('AA.store.proc.Process', {
extend: 'Ext.data.Store',
model: 'AA.model.proc.Process',
requires: 'AA.model.proc.Process'
});
Class:
Ext.define('AA.view.proc.IM', {
extend: 'Ext.window.Window',
alias: 'widget.im',
title: 'IM',
layout: 'fit',
height: 500,
width: 400,
autoShow: true,
plain: true,
modal: true,
headerPosition: 'right',
closable: false,
initComponent: function () {
this.items = [{
xtype: 'form',
fileUpload: true,
width: 550,
autoHeight: true,
border: false,
bodyStyle: 'padding:5px 5px 0',
frame: true,
labelWidth: 100,
defaults: {
anchor: '95%',
allowBlank: false,
msgTarget: 'side'
},
items: [{
xtype: 'combo',
name: 'name',
store: 'procstore',
fieldLabel: 'Name',
valueField: 'name',
displayField: 'name',
width: 150,
allowBlank: true,
listeners: {
scope: this,
'select': this.loadForm
}
}, {
xtype: 'textfield',
fieldLabel: 'Name',
name: 'name'
}, {
xtype: 'textfield',
fieldLabel: 'Owner',
name: 'owner'
}, {
xtype: 'textfield',
fieldLabel: 'E-mail owner',
name: 'mail_dest'
}]
}];
this.buttons = [{
text: 'Save',
action: 'save'
}, {
text: 'Cancel',
scope: this,
handler: this.close
}];
this.callParent(arguments);
},
loadForm: function (field, record, option) {
console.log(record)
// firebug returns
// $className "AA.model.proc.Process"
// $alternateClassName "Ext.data.Record"
console.log(this.down('form'))
// firebug returns the right form panel
this.down('form').loadRecord(record);
}
});
This is from the documentation for the select event:
select( Ext.form.field.ComboBox combo, Array records, Object eOpts )
Notice that the second parameter is an Array. But in your example the second parameter is an Ext.data.Record. You are treating array as a record. Modify your loadForm to make it process arrays of records:
loadForm: function (field,records,option) {
this.down('form').loadRecord(records[0]);
}
P.S. By the way you have two fields with name: 'name'.

Resources