Ext Js Combobox displayTpl is shown twice - extjs

I'm trien to populate a ExtJS 7.3.1 combobox with key/value from an array.
Then I need to display both (Key and Value) on the combobox and the dropdown like this:
var test_store = new Ext.data.SimpleStore({fields : ['value','text'],data : []});
var testArr = [
['test 1', '1'],
['test 2', '2'],
['test 3', '3'],
['test 4', '4'],
]
var combo = Ext.getCmp('test');
test_store = new Ext.data.SimpleStore({
fields: ['value', 'text'],
data: testArr,
});
Ext.create({
xtype: 'formpanel',
renderTo: document.body,
items: [{
xtype: 'combobox',
id: 'test',
name: 'test',
label: 'test',
store: test_store,
displayField: 'text',
valueField: 'value',
queryMode: 'local',
editable: false,
displayTpl: '{value} - {text}',
itemTpl: '<div data-qalign="b-t" data-qanchor="true" data-qtip="{text}">{value} - {text} </div>',
autocomplete: false,
}]
});
But when I unfocus the combobox after I have selected a new value, it will show the displayTpl twice, am I doing something wrong or do I need to report a bug?
fiddle:
https://fiddle.sencha.com/#view/editor&fiddle/3c6i

I really would only override displayTpl or itemTpl if you know what you're doing. In the case of this, I'd say create a separate field and do the conversion there. Like this
var test_store = new Ext.data.SimpleStore({fields : ['value','text'],data : []});
var testArr = [
['test 1', '1'],
['test 2', '2'],
['test 3', '3'],
['test 4', '4'],
]
var combo = Ext.getCmp('test');
test_store = new Ext.data.SimpleStore({
fields: ['value', 'text', {
name: 'display',
type: 'string',
depends: ['value', 'text'],
convert: function(value, record) {
return `${record.get('value')} - ${record.get('text')}`
}
}],
data: testArr,
});
Ext.create({
xtype: 'formpanel',
renderTo: document.body,
items: [{
xtype: 'combobox',
id: 'test',
name: 'test',
label: 'test',
store: test_store,
displayField: 'display',
valueField: 'value',
queryMode: 'local',
autocomplete: false,
anyMatch: true,
forceSelection: true
}]
});

Related

Blank value in Grid with combobox when force select is true

I got a combocox in editor grid. When entering values I have to validate so I used property forceSelection : true . But turning on force selection raise another problem as the combo value is blank when the combo box loss focus as below attached image.
Sample code:
var employeeType = [{
'typeid': 1,
'typename': 'Contractor'
}, {
'typeid': 1,
'typename': 'Regular'
}];
var employeeTypeStore = Ext.create('Ext.data.Store', {
fields: ['typeid', 'typename'],
data: employeeType
});
Ext.define('Employees', {
extend: 'Ext.data.Model',
fields: [{
name: 'emptype',
type: 'string'
}, {
name: 'name',
type: 'string'
},
]
});
var empStore = Ext.create('Ext.data.Store', {
model: 'Employees',
data: [{
'emptype': 'Regular',
'name': 'John Doe'
},{
'emptype': 'Regular',
'name': 'Ricky'
},{
'emptype': 'Regular',
'name': 'Mason'
}]
});
var grid = Ext.create('Ext.grid.Panel', {
renderTo: Ext.getBody(),
store: empStore,
width: 1000,
height: 500,
title: 'Employees',
columns: [{
text: 'Employee Type',
dataIndex: 'emptype',
editor: {
xtype: 'combobox',
queryMode: 'local',
store: employeeTypeStore,
displayField: 'typename',
valueField: 'typeid',
forceSelection : true
}
}, {
text: 'Employee Name',
dataIndex: 'name'
}],
plugins: {
ptype: 'cellediting',
clicksToEdit: 1
}
});
If the value is false then I need to show the last correct value.
Its the Expected behavior.
Setting forceSelection: true will restrict the user to select the value which is present in the list only. So if you loose the focus without selecting any item it will gonna blank.
You can use typeAhead: true to populate and autoselect the remainder of the text being typed if it matches a known value.

How to display a panel based on combobox selection in ExtJS

Here is my code:
{
xtype: 'combo',
width: 150,
value: 'select last..',
store: new Ext.data.SimpleStore({
data: [
[0, 'first'],
[1, 'second'],
[2, 'third']
],
id: 0,
fields: ['value', 'text']
}),
valueField: 'value',
displayField: 'text',
triggerAction: 'all',
editable: false,
name: 'lastComboSelection',
itemId: 'lastCombo',
listeners: {
change: function (combo, newValue, oldValue) {
//based on selection want to display a panel
}
}
},{
xtype: 'firstPanel',
name: 'first text field'
},{
xtype: 'SecondPanel',
name: 'second text field '
},{
xtype: 'thirdPanel',
name: 'last text field '
}
Here is the Change method to select a panel via combo
And here is the simple fiddle example fiddle
Regards:
Salman Hassan :)
listeners: {
change: function(combo, newVal, oldVal, eOpts) {
if (newVal == 'Select Panel 1') {
var panel1 = Ext.ComponentQuery.query("#panel1")[0].show();
var panel2 = Ext.ComponentQuery.query("#panel2")[0].hide();
var panel3 = Ext.ComponentQuery.query("#panel3")[0].hide();
} else if (newVal == 'Select Panel 2') {
var panel1 = Ext.ComponentQuery.query("#panel1")[0].hide();
var panel2 = Ext.ComponentQuery.query("#panel2")[0].show();
var panel3 = Ext.ComponentQuery.query("#panel3")[0].hide();
} else if (newVal == 'Select Panel 3') {
var panel1 = Ext.ComponentQuery.query("#panel1")[0].hide();
var panel2 = Ext.ComponentQuery.query("#panel2")[0].hide();
var panel3 = Ext.ComponentQuery.query("#panel3")[0].show();
}
}
}
If you are using Ext JS version 5.0 or above, then bind the selection property of combobox to activeItem property of a container with panels as its child items. The layout for this container would be card. For example:
Ext.define('OnlyOnePanel', {
extend: 'Ext.panel.Panel',
viewModel: {},
layout: 'vbox',
items: [{
xtype: 'combobox',
width: 150,
emptyText: 'Select..',
store: new Ext.data.SimpleStore({
data: [
[0, 'first'],
[1, 'second'],
[2, 'third']
],
fields: ['value', 'text']
}),
valueField: 'value',
displayField: 'text',
value: 'first',
triggerAction: 'all',
editable: false,
name: 'lastComboSelection',
itemId: 'lastCombo',
bind: {
selection: '{selectedItem}'
}
}, {
xtype: 'container',
layout: 'card',
bind: {
activeItem: '{selectedItem.value}'
},
items: [{
xtype: 'panel',
html: 'First Panel'
}, {
xtype: 'panel',
html: 'Second Panel'
}, {
xtype: 'panel',
html: 'Third Panel'
}]
}]
});
Check this fiddle.

ExtJS 5.0 - Changing combobox displayField at runtime

I have data with two possible display fields: en and fr. Depending on the locale of the user, I'd like to use one or the other as displayField in the combobox, ideally dynamically.
Among many other approaches, I have tried setting displayField to 'en' or 'fr' in initComponent of the combobox, even before this.callParent but it doesn't work right. It might show the correct values in the dropdown, but it won't show it as a selection or sometimes won't even let you select values.
// The sample data
var digits = [
{id: 1, en: 'one', fr: 'un'},
{id: 2, en: 'two', fr: 'deux'},
{id: 3, en: 'three', fr: 'trois'},
{id: 4, en: 'four', fr: 'quatre'},
{id: 5, en: 'five', fr: 'cinq'},
{id: 6, en: 'six', fr: 'six'},
{id: 7, en: 'seven', fr: 'sept'},
{id: 8, en: 'eight', fr: 'huit'},
{id: 9, en: 'nine', fr: 'neuf'},
{id: 10, en: 'zero', fr: 'zéro'}
];
// Define the model for a digit
Ext.define('Digit', {
extend: 'Ext.data.Model',
fields: [
{type: 'integer', name: 'id'},
{type: 'string', name: 'en'},
{type: 'string', name: 'fr'}
]
});
// The data store holding the digits
var store = Ext.create('Ext.data.Store', {
model: 'Digit',
data: digits
});
// Simple form
Ext.create('Ext.form.Panel', {
title: 'Digits',
bodyPadding: 10,
width: 300,
layout: 'anchor',
items: [{
xtype: 'combobox',
fieldLabel: 'Select a digit',
valueField: 'id',
displayField: 'en',
store: store,
queryMode: 'local',
typeAhead: true/*,
// This code will prevent the combobox from working properly.
// Even commenting out this.displayField = 'fr'; mucks it up!
initComponent:
function () {
this.displayField = 'fr';
this.callParent(arguments);
}*/
}],
renderTo: Ext.getBody()
});
I've looked through the component and it appears even in initComponent before calling this.callParent that the combobox is completely initialized.
Is there some other way to set displayField of a combobox at runtime and have it work correctly?
Try this (tested in a fiddle with ExtJS 5.0.0 and 5.0.1):
Ext.create('Ext.form.Panel', {
title: 'Digits',
bodyPadding: 10,
width: 300,
layout: 'anchor',
items: [{
xtype: 'combobox',
fieldLabel: 'Select a digit',
valueField: 'id',
displayField: 'en',
store: store,
queryMode: 'local',
typeAhead: true,
initComponent: function () {
me = this;
me.displayField = 'fr';
this.callParent(arguments);
}
}],
renderTo: Ext.getBody()
});
With ExtJS5.1 this would work fine:
Ext.create('Ext.form.Panel', {
title : 'Digits',
bodyPadding: 10,
width : 300,
layout : 'anchor',
items: [{
xtype : 'combobox',
fieldLabel : 'Select a digit',
valueField : 'id',
displayField: 'en',
store : store,
queryMode : 'local',
typeAhead : true,
listeners: {
render: function(combobox) {
combobox.setDisplayField('fr');
}
}
}],
renderTo: Ext.getBody()
});

ExtJS: cannot call method 'getProxy'

Why does this fail with cannot call method 'getProxy' of undefined?
{
name: 'customer_name',
xtype: 'combobox',
fieldLabel: 'Customer',
emptyText: 'ex. Google',
allowBlank: false,
queryMode: 'local',
store: Ext.create('Ext.data.ArrayStore', {
storeId: 'myStore',
fields: ['name'],
data: [ 'google', 'facebook', 'twitter']
}),
displayField: 'name'
}
taken from docs...
It 100% fails at this peice of code.
The problem is likely that you're defining items on the prototype of your object. You shouldn't do that because it means it will be shared by all instances, also it will try to instantiate your store while defining the class, instead of when the class is instantiated.
Instead of
Ext.define('my.Panel', {
items: {
name: 'customer_name',
xtype: 'combobox',
fieldLabel: 'Customer',
emptyText: 'ex. Google',
allowBlank: false,
queryMode: 'local',
store: Ext.create('Ext.data.ArrayStore', {
storeId: 'myStore',
fields: ['name'],
data: [ 'google', 'facebook', 'twitter']
}),
displayField: 'name'
}
});
Do
Ext.define('my.Panel', {
initComponent: function() {
this.items = {
name: 'customer_name',
xtype: 'combobox',
fieldLabel: 'Customer',
emptyText: 'ex. Google',
allowBlank: false,
queryMode: 'local',
store: {
// Let Ext instantiate the store
type: 'array',
// Don't use this, it's an euphemism for a global
storeId: 'myStore',
fields: ['name'],
data: [ 'google', 'facebook', 'twitter']
},
displayField: 'name'
}
});
I think cause it is missing an end quote in 'name
This code works fine
Ext.widget({
name: 'customer_name',
xtype: 'combobox',
fieldLabel: 'Customer',
emptyText: 'ex. Google',
allowBlank: false,
queryMode: 'local',
store: Ext.create('Ext.data.ArrayStore', {
storeId: 'myStore',
fields: ['name'],
data: [ 'google', 'facebook', 'twitter']
}),
displayField: 'name'
})

extjs checkbox data rendering issue

php return data from server side but not extjs not render the value of fields
i'm using xtype: 'checkbox'
{"total":1,"success":true,"locks":[{"id":"1","record_id":"11","is_unreachable":"1","is_directory_Lock":"1","is_Internet_Lock":"0","is_partner_Lock":"1","is_home_business":"1","is_top_listing":"1","is_mole":"1","is_pre_call":"1","is_new_business":"1","is_free_adv":"1","is_verified":"1","is_reviewed":"1","is_idr":"1"}]}
json array return from server
you have to paste you code.
But why not go to the example:
http://docs.sencha.com/ext-js/4-0/#!/example/grid/array-grid.html
Ext.define('UserApp.view.uiTypes.LockFeature',{
extend: 'Ext.form.Panel',
collapsible: true,
flex: 1,
height: 200,
width: 600,
store: null,
itemId: 'lockfeature',
layout:{
type: 'table',
columns: 3
},
items:[{
xtype: 'checkbox',
boxLabel: 'Is Unreachable',
name: 'is_unreachable',
id: 'is_unreachable',
dataIndex: 'is_unreachable',
inputValue: 'true',
uncheckedValue: 'false',
value: true,
},{
xtype: 'textfield',
name: 'is_unreachable_update',
fieldLabel: 'Last Update',
},{
xtype: 'textfield',
name: 'update_by_user',
fieldLabel: 'By'
}],
initComponent: function(){
console.log(this.table);
console.log(this.record_id);
var table = this.table;
var parentTable = table.split('_');
console.log(parentTable[0]);
var store = Ext.create('UserApp.store.LockFeature');
store.getProxy().setExtraParam('table',parentTable[1]);
store.getProxy().setExtraParam('tab',parentTable[1]);
store.getProxy().setExtraParam('saving_table', table);
store.getProxy().setExtraParam('record_id',this.record_id);
this.store = store;
this.callParent(arguments);
store.load();
}
});

Resources