How to search item with keyboard letter key in extjs combobox? Javascript - javascript

I have a combobox I can get all data I want but when i enter a letter, the data should be choosen in combobox
forexample,my variables: ankara, aston, amasya, bolu, berlin, ....
When i enter 'a' letter ankara should be selected. if i enter 'as' word aston should be selected how can i do it? thanks..
new Ext.form.ComboBox({
id : 'il3',
fieldLabel: dil('B Merkez İli'),
hiddenName : 'b_il_id_hid',
name : 'b_il_id',
store: ilStore,
valueField:'id',
queryMode: 'local',
displayField:'isim',
typeAhead: true,
triggerAction: 'all',
emptyText: dil('İl Seçiniz...'),
selectOnFocus:true,
anchor: '100%',
listeners:{
select:{
fn:function(combo, value) {
var modelCmp = Ext.getCmp('ilce3');
modelCmp.setDisabled(false);
modelCmp.store.removeAll();
modelCmp.setValue('');
modelCmp.store.reload({
params: {
id: combo.getValue()
}
});
}
}
},
allowBlank:false
})
store:
var ilStore = new Ext.data.JsonStore({
root: 'rows',
totalProperty: 'results',
idProperty: 'id',
remoteSort: true,
autoLoad : true,
fields: [
'id', 'isim'
],
baseParams:{
'tip':'il'
},
listeners:{
beforeload:function(dukan,nesne){
var modelCmp = Ext.getCmp('id-faz-yon1');
dukan.baseParams.faz = modelCmp.getValue();
},
keyup: function() {
this.store.filter('isim', this.getRawValue(), true, false);
}
},
proxy: new Ext.data.HttpProxy({
url: 'phps/sabit_agac_arama.php?lang=dil(lang)',
method : 'POST'
})
});

Add queryMode: 'local', to the config.
See the example in the API

Related

Setting a Default Value to a ComboBox using Json in ExtJS 3.4

I am trying to set a default value in a ComboBox in ExtJS 3.4 I have tried to set value: 'Standard' in the ComboBox config, but that only places a string in the box. I did some digging around and tried to setup the afterrender function, but still haven't gotten it to populate. The goal is to get the box to actually select the value and populate the box with the Json data, so that the user is able to select from subsequent ComboBoxes.
var hatComboStore = new Ext.data.JsonStore({
autoLoad: true,
fields: [
'BIN_ID',
'BIN_DESC'
],
baseParams: {
method: 'post'
},
url: 'json_bin_hat.php'
});
var hatCombo = new Ext.form.ComboBox({
allowBlank: false,
autoSelect: true,
displayField: 'BIN_DESC',
emptyText: 'Select a hat...',
fieldLabel: 'Hat',
forceSelection: false,
hiddenName: 'hatId',
itemId: 'hatId',
listEmptyText: 'No records found',
listeners: {
afterrender: function(combo, record, index) {
var hat = combo.getValue();
binCombo.store.baseParams.hat = hat;
},
select: function(combo, record, index) {
var hat = combo.getValue();
binCombo.store.baseParams.hat = hat;
},
focus: function(combo) {
binCombo.clearValue();
}
},
mode: 'remote',
msgTarget: 'side',
name: 'hatDesc',
store: hatComboStore,
submitValue: true,
triggerAction: 'all',
valueField: 'BIN_ID'
});
Anyone have any ideas? Thanks for your help!
I've got it to work using an override method.
Basically, the displayValue is what I wanted to display ('Standard') and the value is what I wanted to execute (value: 1). Apparently, the remote store is a little tricky to work with, so that's why the override was necessary.
var hatComboStore = new Ext.data.JsonStore({
autoLoad: true,
fields: [
'BIN_ID',
'BIN_DESC'
],
baseParams: {
method: 'post'
},
url: 'json_bin_hat.php'
});
var hatCombo = new Ext.form.ComboBox({
allowBlank: false,
autoSelect: true,
displayField: 'BIN_DESC',
displayValue: 'Standard',
emptyText: 'Select a hat...',
fieldLabel: 'Hat',
forceSelection: false,
hiddenName: 'hatId',
itemId: 'hatId',
listEmptyText: 'No records found',
listeners: {
afterrender: function(combo, record, index) {
var hat = combo.getValue();
binCombo.store.baseParams.hat = hat;
},
select: function(combo, record, index) {
var hat = combo.getValue();
binCombo.store.baseParams.hat = hat;
},
focus: function(combo) {
binCombo.clearValue();
}
},
mode: 'remote',
msgTarget: 'side',
name: 'hatDesc',
store: hatComboStore,
submitValue: true,
triggerAction: 'all',
valueField: 'BIN_ID'
value: 1
});
//Override method to default hatCombo value to 'Standard' while underlying value = 1
Ext.override(Ext.form.ComboBox, {
initValue: Ext.form.ComboBox.prototype.initValue.createSequence(function() {
if (this.mode == 'remote' && !!this.valueField && this.valueField != this.displayField && this.displayValue) {
if (this.forceSelection) {
this.lastSelectionText = this.displayValue;
}
this.setRawValue(this.displayValue);
}
})
});
Looks like the value prop is not working for remote stores. Probably the combo is rendered before the store has loaded. You can set the value after the store has loaded.
This works for me (tested as an ExtJS 3.4 fiddle).
var hatComboStore = new Ext.data.JsonStore({
autoLoad: true,
fields: [
'id',
'title'
],
url: 'https://jsonplaceholder.typicode.com/todos'
});
var hatCombo = new Ext.form.ComboBox({
fieldLabel: 'Hat',
store: hatComboStore,
displayField: 'title',
valueField: 'id',
mode: 'local',
submitValue: true,
triggerAction: 'all',
// Apparently does not work with remote store.
// value: '1'
});
hatComboStore.on('load', () => hatCombo.setValue('1'));
new Ext.form.FormPanel({
items: hatCombo,
renderTo: Ext.getBody()
});
see example of setting default value:
Combo config:
{
triggerAction: 'all',
id: 'dir_id',
fieldLabel: 'Direction',
queryMode: 'local',
editable: false,
xtype: 'combo',
store : dirValuesStore,
displayField:'name',
valueField:'id',
value: 'all',
width: 250,
forceSelection:true
}
source: Extjs 4 combobox default value

after change Combobox pagination, getValue and getRawValue returned the same value

I use Ext js 3.4 combobox finder.
Suppose that the combobox's store uses pagination.
As first, when I select some item, it gives me i.e.: getValue() => 1000 and getRawValue() => "Item Name", but after I change pagination (without selecting any item) the getValue() method returns "Item Name".
Can anyone help me?
Combobox = Ext.extend(Ext.form.ComboBox, {
allowBlank: false,
autoSelect: false,
baseParams: {},
cls: "remote-server-finder",
displayField: 'name',
emptyText: "",
forceSelection: false,
itemSelector: 'div.remote-server-finder-item',
minChars: 0,
pageSize: 10,
queryDelay: 10,
store: null,
triggerAction: 'all',
typeAhead: true,
valueField: 'id',
minListWidth: 235,
maxHeight: 400,
/**
* Setup the data store and template for the finder.
*/
initComponent: function () {
this.blankText = helpsys.locale.javascript.field_required;
this.loadingText = helpsys.locale.common.searching;
this.listEmptyText = helpsys.locale.javascript.no_matching_record;
this.store = new Ext.data.JsonStore({
baseParams: this.baseParams,
fields: [
{
name: 'id'
},
{
name: 'name'
},
{
name: 'description'
},
{
name: 'type'
}
],
idProperty: 'id',
proxy: new Ext.data.HttpProxy({
url: this.url,
method: 'GET',
listeners:{
beforeload:{
scope:this,
fn:function(dp, params){
if(dp.activeRequest['read']){
dp.activeRequest['read'].conn.abort();
}
}
}
}
}),
root: 'items',
totalProperty: "totalResultsAvailable"
});
this.tpl = new Ext.XTemplate('<tpl for="."><div class="remote-server-finder-item finder-item x-combo-list-item">',
'<div class="remote_server_finder_text finder_text">', '<h2 class="name">{name}</h2>', '<p class="description">{description}</p>', '</div>', '</div></tpl>');
);
}

ComboBox is not working in an EditorGridPanel for ExtJS

I am new to ExtJS and need to put a ComboBox in an EditorGridPanel.
My code so far does not create the combobox in the EditorGridPanel and the EditorGridPanel does not display as well.
Here is the code and thanks for your help. capturetheflag
/*==== INVOICE DATA START =======================================================*/
/* create the ComboBox editor */
var idCombo = new Ext.form.ComboBox({
id: 'id',
valueField: 'id',
displayField:'id',
store: '', //what do I store here??
triggerAction: 'all'
});
var idRenderer = function(value,metaData,record){
// try record.data.teacher here
return "displayValue"
var iLineItemCM = new Ext.grid.ColumnModel([
{
id: 'i_line_item_id',
header: 'Line Item ID',
dataIndex: 'i_line_item_id',
width: 80,
editor: this.idCombo(),
renderer:idRenderer
}
,{
id:'i_line_item_name',
header: "Line Item Name",
dataIndex: 'i_line_item_name',
width: 315,
resizable: true,
align: 'center',
editor: new Ext.form.TextArea({
allowBlank: false
})
}
,{
header: "Amount",
dataIndex: 'i_line_item_amt',
width: 80,
align: 'right',
renderer: 'usMoney',
editor: new Ext.form.NumberField({
allowBlank: false,
allowNegative: false,
maxValue: 100000
})
}
]);
var iLineItemRec =
new Ext.data.Record.create([
{
name: 'i_line_item_id' ,
mapping: 'i_line_item_id' ,
type: 'string'
}
,{
name: 'i_line_item_name' ,
mapping: 'i_line_item_name' ,
type: 'string'
}
,{
name: 'i_line_item_amt' ,
mapping: 'i_line_item_amt' ,
type: 'string'
}
]);
var iLineItemStore = new Ext.data.Store({
url: '',
reader: new Ext.data.JsonReader({
root: 'rows'
},
iLineItemRec
)
});
var iLineItemGrid = new Ext.grid.EditorGridPanel({
id: 'iLineItemStore',
store: iLineItemStore,
cm: iLineItemCM,
cls: 'iLineItemGrid',
width: 'auto',
height: 'auto',
frame: true,
//title:'Edit Plants?',
//plugins:checkColumn,
clicksToEdit:1,
viewConfig: {
//forceFit: true
autoFit:true
},
tbar: [{
text: 'Add',
tooltip:'Add the line item',
handler : function(){
var r = new iLineItemRec({
i_line_item_name: '',
i_line_item_amt: ''
});
iLineItemGrid.stopEditing();
iLineItemStore.insert(0, r);
iLineItemGrid.startEditing(0, 0);
}
},
{
text: 'Delete',
tooltip:'Remove the selected line item',
handler: function(){
iLineItemGrid.stopEditing();
var r = iLineItemGrid.getSelectionModel().getSelectedCell();
iLineItemStore.removeAt(r[1]);
}
}
]
});
/////////////////// CODE ENDS
You need to create a data store and bind that to your combobox. Then in the combo config, you can tell it which field from the store you want to display and which field you want for the value. Here is an example from ExtJS 4 API Docs:
// The data store containing the list of states
var states = Ext.create('Ext.data.Store', {
fields: ['abbr', 'name'], // fields that your data consists of
data : [
{"abbr":"AL", "name":"Alabama"},
{"abbr":"AK", "name":"Alaska"},
{"abbr":"AZ", "name":"Arizona"}
//...
]
});
// Create the combo box, attached to the states data store
var combo = Ext.create('Ext.form.ComboBox', {
fieldLabel: 'Choose State',
store: states, // here you use the store
queryMode: 'local',
displayField: 'name', // you tell your combobox which field to display from the store
valueField: 'abbr', // you tell your combobox which field to use for value from the store
renderTo: Ext.getBody()
});
If you use combo.getValue(), and if e.g. "Alaska" were selected in your combobox, it would return "AK". You can also use the same field as displayField and valueField if you like.

emptyText is submitted with the form

I am using Ext Js 3.4. I run into a problem when using myform.getForm.getValues()
emptytext is also sent in the request.
Below is the code snippets
myForm = new Ext.FormPanel({
id: 'myForm ',
items: [
{
region:'center',
border:false,
items:[center_one]
},{
region:'west',
border:false,
items :[west_one]
},{
region:'east',
border:false,
items :[east_one]
},{
region:'south',
layout:'table',
iborder:false,
items: [south_one]
}
]
});
var west_one= new Ext.form.FieldSet({
width: 282,
height:250,
layout: 'table',
items: [{
id: 'form1',
layout: 'form',
items: [field1]
},{
id: 'form2',
layout: 'form',
items: [field2]
}]
});
var field1 = new Ext.form.ComboBox({
fieldLabel: 'Field',
width: 150,
name: 'field1',
cls: 'fields field1',
id: 'field1',
store: field1Store,
displayField: 'name',
valueField: 'name',
mode: 'local',
emptyText: 'Select Field1', // This value gets submiited when no value is selected
selectOnFocus: true,
triggerAction: 'all',
forceSelection : true,
editable:true,
typeAhead:true,
});
And this is how I submit:
Ext.Ajax.request({
url: 'forms.do?submit',
method: 'POST',
params: myForm.getForm().getValues(),
success: function(response, option){
},
failure: function(){
}
});
You will Need to add this config in submitform xtype :
submitEmptyText: false
By defalut submitEmptyText is set to true.
Check it on Online Documentation HERE.
EDIT:try the following code instead of Ext.ajax:
var myForm = Ext.getCmp('myForm').getForm();
myForm.submit({
url : 'forms.do?submit',
method : 'POST',
fileUpload : true,
submitEmptyText : false,
// waitMsg : 'Saving data',
success : function(form, action) {}
});
If you just want to get the values without emptytext (for example to submit them using Ext.Ajax as in your question), use myForm.getForm().getFieldValues().

ExtJs combo forced to select the first item (with example code)

I have a combo B that gets loaded by other combo A (triggered by 'select' listener)
once B is populated, I see all items but now from drop-down in Combo B,
I'm force to select the first item with mouse
I can select other item only by typing
Please help!!!!
code for Combo A
{
xtype: 'combo',
displayField: 'value',
emptyText: 'Please select A first',
fieldLabel: 'Combo A',
id: 'comboA',
maxHeight: 240,
mode: 'local',
triggerAction: 'all',
typeAhead: true,
typeAheadDelay: 100,
valueField: 'id',
store: new Ext.data.JsonStore({
url: '/cgi-bin/server.cgi',
fields: ['id', 'name'],
baseParams: {
action: 'getAList'
},
autoLoad: true,
root: 'aList'
}),
listeners: {
'select': {
fn: function(){
var comboB = Ext.getCmp('comboB');
comboB.clearValue();
comboB.store.removeAll();
comboB.store.reload({
params: {
id: this.getValue()
}
})
}
}
}
}
Code for combo B:
{
xtype: 'combo',
displayField: 'item',
editable: true,
emptyText: 'Select a Combo A first',
fieldLabel: 'Combo B',
id: 'comboB',
lazyInit: true,
maxHeight: 240,
mode: 'local',
triggerAction: 'all',
typeAhead: true,
valueField: 'id',
width: 220,
store: new Ext.data.JsonStore({
url: '/cgi-bin/server.cgi',
root: 'bList',
autoLoad: false,
fields: ['id,', 'item'],
baseParams: {
action: 'getBList'
},
listeners: {
'beforeload': function(){
Ext.getCmp('comboB').disable();
},
'load': function(){
Ext.getCmp('comboB').enable();
}
}
})
}
Not sure what exactly is wrong here but I suspect this piece in your comboA is not getting fired as expected -
comboB.store.reload({
params: {
id: this.getValue()
}
})
So comboB is still disabled. when you click on the comboB trigger, it loads the store and the comboB's store's load listener is kicking in as expected to enable the combo.
Try putting some debug statements or stepping through the piece of code above.

Categories