Combobox <Extjs4 - Empty line - extjs

Before starting I am sorry with my english.. I don't speak it well ..
So I have a problem with the Combobox in ExtJS4 .. I tried to add a empty line in my combobox list but It's not ok .. i have the list with a empty line but when I trie to select it I can't.. so if someone can help me or have an example please
Ext.require([
'Ext.form.*',
'Ext.data.*',
'Ext.tip.QuickTipManager'
]);
Ext.onReady(function () {
Ext.QuickTips.init();
var form = Ext.create('Ext.form.Panel', {
renderTo: 'docbody',
title: ' ',
autoHeight: true,
width: 600,
bodyPadding: 10,
defaults: {
anchor: '100%',
labelWidth: 100
},
items: [{
xtype: 'fieldcontainer',
combineErrors: true,
msgTarget: 'side',
fieldLabel: ' Name',
items: [{
width: 50,
xtype: 'combo',
mode: 'local',
triggerAction: 'all',
forceSelection: true,
editable: false,
selectOnFocus: true,
name: 'title',
displayField: 'name',
valueField: 'value',
tpl: '<tpl for="."><div class="x-combo-list-item">{name:defaultValue("--")}</div></tpl>',
queryMode: 'local',
store: Ext.create('Ext.data.Store', {
fields: ['name', 'value'],
data: [{
name: 'Mvr',
value: 'mr'
}, {
name: 'Mrs',
value: 'mrs'
}, {
name: 'Miss',
value: 'miss'
}],
listeners: {
'load': function (store, records, options) {
this.insert(0, '--');
}
}
})
}]
}]
});
});

Unless adding a record to your store will break something else in your program logic, I would suggest doing that and getting rid of the template.
Ext.require([
'Ext.form.',
'Ext.data.',
'Ext.tip.QuickTipManager'
]);
Ext.onReady(function() {
Ext.QuickTips.init();
var form = Ext.create('Ext.form.Panel', {
renderTo: Ext.getBody(),
title : ' ',
autoHeight: true,
width : 600,
bodyPadding: 10,
defaults: {
anchor: '100%',
labelWidth: 100
},
items : [
{
xtype : 'fieldcontainer',
combineErrors: true,
msgTarget: 'side',
fieldLabel: ' Name',
items : [
{
width: 50,
xtype: 'combo',
mode: 'local',
triggerAction: 'all',
forceSelection: true,
editable: false,
selectOnFocus : true,
name: 'title',
displayField: 'name',
valueField: 'value',
//tpl: '<tpl for="."><div class="x-combo-list-item">{name:defaultValue("--")}</div></tpl>',
queryMode: 'local',
store: Ext.create('Ext.data.Store', {
fields : ['name', 'value'],
data : [
{name : 'Mr', value: 'mr'},
{name : 'Mrs', value: 'mrs'},
{name : 'Miss', value: 'miss'}
],
listeners :
{
'load' : function (store, records, options) {
store.add({name: '--', value: null});
}}
})
}
]
}
]
});
});​

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'));

Not getting data in Ext JS form Panel

function open() {
var req_spec_store = new Ext.data.SimpleStore({
url: 'mngr_req_ajx.php',
fields: ['value', 'text'],
data: [
['Android', 'Android'],
['iPhone', 'iPhone'],
['iPhone2', 'iPhone2'],
['iPhone3', 'iPhone3']
]
});
req_spec_store.load({
params: {
todo: 'Get_Req_Spec'
}
});
var menuWin = new Window('menuWindow', {
title: "Create Data",
width: 980,
height: 340,
draggable: true,
destroyOnClose: true,
hideEffect: Element.hide,
showEffect: Element.show,
minimizable: false,
maximizable: false,
closable: true,
resizable: false,
items: [new Ext.FormPanel({
renderTo: 'r_sp',
id: 'mngReqForm',
layout: 'form',
height: innerHeight - 250,
width: innerWidth - 50,
frame: true,
destroyOnClose: true,
defaults: {
msgTarget: 'side',
labelSeparator: ''
},
labelAlign: 'right',
items: [{
xtype: 'combo',
fieldLabel: 'Data Entry ',
store: req_spec_store,
displayField: 'text',
valueField: 'value',
mode: 'local',
emptyText: 'Select Entry...',
triggerAction: 'all',
name: 'specId2',
id: 'specId2',
hiddenName: 'specIdHid',
width: 150,
forceSelection: false,
editable: false,
selectOnFocus: true
}]
})]
});
}
window is opened in on click of button. Inside window, there is form panel. Which is having one combo type element. I am calling PHP using ajax, getting data successfully when directly doing the stuff on Ext.onReady() but not in case of window opened.
The data of your store should be in JSON (also {} instead off []=
data : [ {value:'Android', text:'Android' }, ... ]

extjs 3.4 data not displaying from a popup grid to the main grid

I have a grid in which I want to filter some results. For filtering the result a popup is opened and the user can select the search criteria and filter the results. The php file is executed as well as the result is returned to the popup, but it is not displaying in the main grid. Here is my code.
This code displays the grid and is displaying the result when the user selects the radio button for filtering purpose :
var checkModel = new xg.CheckboxSelectionModel();
var orderGridPanel = {
id: 'orderGridPanel',
xtype: 'editorgrid',
title: 'Orders',
height:350,
clicksToEdit: 2,
frame: true,
viewConfig: {
forceFit:true
},
cm: new xg.ColumnModel({
defaults: {
width: 120,
sortable: true
},
columns: [
{header:"nr",dataIndex:'nr',hidden:true}
,checkModel
,{header:"Order Id",dataIndex:'order'}
,{header:"Order Date",dataIndex:'date', renderer:Ext.util.Format.dateRenderer('m/d/Y')}
,{id:'created_by',header:"Order By",dataIndex:'created',align:'left'}
,{id:'order_type',header:"Order Source",dataIndex:'order',align:'left'}
,{header:"Order Type", dataIndex:'category'}
,{header:"Sub Category",dataIndex:'sub_cate_nm'}
,{header:"Item",dataIndex:'item'}
,{header:"Properties",dataIndex:'order'}
,{header:"Status",dataIndex:'order'}
,{header:"Action",renderer: renderViewResults}
]
}),
sm: checkModel,
store: new Ext.data.Store({
root: 'results',
method: 'POST',
autoSave: false,
batch: true,
proxy: new Ext.data.HttpProxy({
api: {
read: 'results.php?task=LISTING',
create: 'results.php?task=CREATE',
update:'results.php?task=UPDATE',
destroy: 'results.php?task=DELETE'
}
}),
writer: new Ext.data.JsonWriter({
encode: true,
writeAllFields: true,
batch: true
}),
reader: new Ext.data.JsonReader({
totalProperty: 'total',
successProperty: 'success',
idProperty: 'nr',
root: 'results',
fields: ['nr','order','date', 'created', 'type', 'category', 'sub_category_nm', 'item', 'properties', 'status']
}),
baseParams: ahist_order_params
}),
bbar:[
'-',{
text: 'Add',
iconCls: 'icon-add',
handler: function(){
editMoreData(0);
}
},
'-', {
text: 'Search',
iconCls: 'icon-search',
handler: function(){
displaySearchFilter(origid);
}
},
'-',{
text: 'Sign Orders',
iconCls: 'icon-warning',
handler: function(){
displaySearchFilter();
}
},
'-',{
text: 'Cancel',
iconCls: 'icon-delete',
handler: function(){
displaySearchFilter();
}
},
'-', {
text: 'Refresh',
iconCls: 'icon-table_refresh',
handler: function(){
Ext.getCmp('orderGridPanel').stopEditing(false);
var rs = orderGridPanel.store.getModifiedRecords();
if (rs.length > 0) {
var status = window.confirm("Some data modified on grid, do you want to save grid data before loading latest data ?");
if (status){
orderGridPanel.store.save();
}
}
orderGridPanel.store.load();
}
},
'-', {
text: 'Print',
iconCls: 'icon-print',
handler: function(){
statusStr = getHistGridSelection();
}
}
,'->'
,'Display:','-',
{
xtype: 'radio',
name: 'search_filter',
id:'search_filter_1',
inputValue: 1,
boxLabel: 'Open Orders',
handler: onChangeLoadFilter ,
checked : true
},'-',{
xtype: 'radio',
name: 'search_filter',
id:'search_filter_2',
inputValue: 2,
boxLabel: 'All Orders',
handler: onChangeLoadFilter
},'-',{
xtype: 'radio',
name: 'search_filter',
id:'search_filter_3',
inputValue: 3,
boxLabel: 'Orders 5 days back',
handler: onChangeLoadFilter
}
,'-',{
xtype: 'radio',
name: 'search_filter',
id:'search_filter_4',
inputValue: 4,
boxLabel: 'Cancelled Orders',
handler: onChangeLoadFilter
}
]
};
Now when I click on the search button this code executes:
function displaySearchFilter(id){
var formPanel = new Ext.FormPanel({
frame: true,
labelWidth:150,
bodyStyle: 'padding:5px 5px 0',
items: [{
xtype: 'fieldset',
defaultType: 'textfield',
items: [
{
xtype : 'container',
border : false,
layout : 'column',
anchor : '100%',
style : 'margin-top:8px;margin-bottom:8px;',
defaultType : 'field',items :[
{
xtype: 'label',
style: 'float: left; margin-left:3px;margin-top:3px;',
text: 'From'
},
{
fieldLabel: 'From Date',
xtype: 'datefield',
id: 'from_date',
style: "float: left; margin-left:3px;",
width:70
},
{
xtype: 'label',
style: 'float: left; margin-left:5px;margin-top:3px;',
text: 'To'
},
{
fieldLabel: 'To Date',
xtype: 'datefield',
id: 'to_date',
style: 'float: left; margin-left:5px;',
width:70
},
{
xtype: 'label',
style: 'float: left; margin-left:5px;margin-top:3px;',
text: 'Patient'
},
{
fieldLabel: 'Patient ID',
id:'patient',
xtype: 'textfield',
style: 'float: left; margin-left:5px;',
value: btpacs.data.Origid,
mode:'local'
},
{
xtype:'label',
style:'float:left;margin-left:5px;margin-top:3px;',
text:'Display'
},
{
xtype:'combo',
id:'search_filter',
store:btpacs.data.searchFilter,
typeAhead: true,
mode: 'local',
triggerAction: 'all',
selectOnFocus: true,
lastQuery: '',
emptyText:'Select an option...',
width : 120
}
]},
{
xtype: 'combo',
fieldLabel: 'Order Type',
name: 'category',
id:'cat',
store: btpacs.data.CpoeCategory,
hiddenName: 'category',
triggerAction: 'all',
emptyText:'Select an option...',
width : 300,
mode: 'local',
lastQuery: '',
listeners : {
select : function (f, e){
//params: { cat_id: Ext.getCmp('cat').getValue()}
//subCategoryStore.load();
var category_id = Ext.getCmp('cat').getValue();
subCategoryStore.reload({
params: { cat_id: category_id}
});
}
}
},
{
xtype: 'multiselect',
fieldLabel: 'Sub Category',
name: 'sub_category',
id:'sub_cat',
displayField: 'sub_cat_name',
valueField: 'sub_cat_id',
store: subCategoryStore,
hiddenName: 'sub_category',
emptyText:'Select Order Type First...',
triggerAction: 'all',
width : 300,
mode: 'local',
listeners : {
click : function (f, e){
var sub_cat_id = Ext.getCmp('sub_cat').getValue();
itemStore.reload({
params: { sub_cat_ids: sub_cat_id}
});
}
}
},
{
xtype: 'multiselect',
fieldLabel: 'Items',
name: 'items',
displayField: 'item_name',
valueField: 'item_id',
store:itemStore,
hiddenName: 'items',
triggerAction: 'all',
width : 300,
mode: 'local'
},
{
xtype : "multiselect",
fieldLabel : "Doctor List",
id: 'placed_doctor_name',
displayField: 'name',
valueField: 'name',
typeAhead: true,
mode: 'local',
triggerAction: 'all',
selectOnFocus: true,
lastQuery: '',
store:doctorStore,
width : 300
}]
}],
buttons: [{
text: 'Search',handler: function() {
formPanel.getForm().submit({
method: 'POST',
url: 'ajax/results.php?task=SEARCH', // when this file is executed the result is return properly as I want
root: 'results',
params : {'origid': origid},
success: function(f, a) {
// after the result is successfully returned I cannot display it here.I am not sure what I am missing.Here I want to assign all the result to orderGridPanel
win.close();
},
failure: function(f, a) {
alert("Request failed");
f.markInvalid(a.result.errors);
}
});
}
},
{
text: 'Cancel',
handler: function () {
win.close();
}
}]
});
win = new Ext.Window({
layout: 'fit',
width: 650,
height: 520,
defaults: {
autoScroll: true
},
closeAction: 'close',
title: 'Search Orders',
plain: true,
items: [formPanel]
});
win.show();
}
Thanks in advance.
You need to load the data into the store of the grid if you want the grid to display the data.

Data Store has empty data property

I am working with Ext.js and trying to get a data Store set up and mapped to data fields on my FormPanel so that I can easily acess data input.
Something is missing in my mapping:
When I enter data in the textfields and hit my Submit button's submit handler, the data property on the store is blank. I was expecting it to contain data input on the page. Can someone help? Thanks very much:
infoPanel = function () {
this.store = new Ext.data.JsonStore({
autoLoad: true,
root: 'Data',
storeId: 'creditMemoStore',
fields: ['shipto', 'billto', 'reasonCode', 'creditClaimed', 'adjustmentAmount', 'poNumber']
});
this.fieldset = {
xtype: 'fieldset',
flex: 1,
border: false,
defaultType: 'field',
items: [
{
xtype: 'textfield',
labelWidth: 160,
fieldLabel: 'Ship to',
name: 'shipto',
//dropdown
allowBlank: false
},
{
xtype: 'textfield',
labelWidth: 160,
fieldLabel: 'Bill to',
name: 'billto',
//dropdown
allowBlank: false
},
{
xtype: 'textfield',
labelWidth: 160,
fieldLabel: 'Reason Code',
name: 'reasonCode',
//dropdown
allowBlank: false
},
{
labelWidth: 160,
xtype: 'numberfield',
allowNegative: false,
fieldLabel: 'Amount',
allowBlank: false,
name: 'creditClaimed'
},
{
labelWidth: 160,
xtype: 'numberfield',
allowNegative: false,
fieldLabel: 'Adjustment Amount',
name: 'adjustmentAmount',
allowBlank: false,
maxLength: 5
},
{
xtype: 'textfield',
labelWidth: 160,
fieldLabel: 'Customer PO Number',
allowBlank: false,
name: 'poNumber',
maxLength: 15
},
{
xtype: 'textfield',
labelWidth: 160,
fieldLabel: 'Debit Memo Number',
allowBlank: false,
name: 'dmNumber',
maxLength: 50
},
{
xtype: 'textfield',
labelWidth: 160,
fieldLabel: 'Credit Memo Number',
allowBlank: false,
name: 'cmNumber',
maxLength: 6
},
{
xtype: 'textfield',
labelWidth: 160,
fieldLabel: 'Currency Code',
name: 'currencyCode',
//dropdown
allowBlank: false,
maxLength: 3,
value: 'USD'
}
]
};
this.panel = new Ext.form.FormPanel({
renderTo: Ext.getBody(),
width: 700,
title: 'Create Credit Memo',
height: 400,
frame: true,
id: 'creditMemoFormPanel',
layout: 'vbox',
layoutConfig: {
align: 'stretch'
},
items: [
this.fieldset
],
store: this.store,
buttons: [
{
text: 'Reset',
handler: function () {
this.up('form').getForm().reset();
}
},
{
text: 'Submit',
formBind: true,
handler: function () {
var form = this.up('form').getForm();
var store = Ext.StoreMgr.get('creditMemoStore');
var dataObject = { testPost: store.data};
if (form.isValid()) {
Ext.Ajax.request({
url: 'CreateCreditMemo',
jsonData: Ext.JSON.encode(dataObject),
success: function() { Ext.Msg.alert('json post Success'); },
failure: function () { Ext.Msg.alert('json post Fail'); },
});
}
}
}
]
});
}
Ext.onReady(function () {
var ip = new infoPanel();
});
The Ext.js Store is only used for records where more than set of data is displayed at a time.
The Store doesn't apply to a basic form. The Ext.js Form posts the values of all of the fields automatically on submit.

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