emptyText is submitted with the form - javascript

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().

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

Extjs combobox to display records with value fetched from data store rest/jsp request

With ExtJs (4.2) version, wanted to know how to filter the empty records from the combobox dropdown list.
The code uses Extjs store to fetch a data from jsp, the result is a json object. Say below is the results rendered,
{ "data" : [
{"source":"system1","key1" : "value system1", "key2" : " value for system1"},
{"source":"system2","key1" : "value 11", "key2" : " value for key1, value 12"},
{"source":"system3" }, //Blank or empty key1, key2 record.
....
}
Js code with ExtJs
I am using ExtJs to display a combobox (Dropdown) below is the code fragment
var dataStore = Ext.create('Ext.data.Store', {
autoLoad: true,
fields: ['key1', 'key2'],
proxy:
{
type: 'ajax',
url: '<url to a jsp file which retruns json data>',
reader:
{
type: 'json',
root: 'templates'
}
}
});
...
var screenPanel = {
xtype: 'fieldset',
title: 'Panel - Data',
margin: '0 10 15 15',
padding: 10,
flex: 1,
width:"100%",
layout: 'anchor',
defaults: {
labelWidth: 160,
},
items: [
{
xtype: 'checkbox',
name: 'visibility',
id: 'visibility',
fieldLabel : 'Check to enable',
value:false
},
{
xtype: 'combobox',
anchor: '80%',
name: 'combodropdown',
itemId: 'combo1',
fieldLabel: 'Dropdown selection',
displayField: 'key2',
valueField: 'key1',
store: dataStore,
},{
xtype: 'container',
anchor: '80%',
....
The combox dropdown is listing the empty record as well. Is there a way to filter that value. In the above case the "source" : "system3" doesn't have key1 and key2 value but the xtype:combo (name: combodropdown) is listing a blank item as well.
Is there any example, on using an event to filter the data that are empty. like onClick event to filter the data like below
....
{
xtype: 'combobox',
anchor: '80%',
name: 'combodropdown',
itemId: 'combo1',
fieldLabel: 'Dropdown selection',
displayField: 'key2',
valueField: 'key1',
store: dataStore,
//some thing like this
onClick: function(value1,value2){
alert('clicked combox dropdown')
//data store value empty return something
}
You can use store filter. Something like:
Ext.application({
name: 'Fiddle',
launch: function () {
var dataStore = Ext.create('Ext.data.Store', {
autoLoad: true,
fields: ['key1', 'key2'],
proxy: {
type: 'ajax',
url: 'comboData.json',
reader: {
type: 'json',
root: 'data'
}
},
filters: [
function (item) {
return !Ext.isEmpty(item.get('key1')) && !Ext.isEmpty(item.get('key2'));
}
]
});
Ext.create('Ext.form.Panel', {
title: "Sample Panel",
items: [{
xtype: 'combobox',
name: 'combodropdown',
itemId: 'combo1',
fieldLabel: 'Dropdown selection',
displayField: 'key2',
valueField: 'key1',
store: dataStore,
listeners: {
expand: function(comboBox) {
console.log(comboBox.getStore().getRange());
}
}
}],
renderTo: Ext.getBody()
})
}
});

Send Ajax request onFocus of a ComboBox rather than on typing

xtype : 'combo',
allowBlank : false,
hideTrigger : true,
name : 'dummyName',
itemId : 'value',
fieldLabel : 'Value',
labelWidth: 40,
store : {
fields : ['value'],
proxy : {
type: 'ajax',
url: '/DUMMY/URL/',
reader: {
type: 'json',
rootProperty: 'results'
}
}
},
displayField: 'value',
valueField : 'value',
queryMode : 'remote',
queryParam : 'search',
typeAhead : false,
minChars : 0,
queryDelay : 500,
emptyText : 'mandatory',
msgTarget : 'none',
listConfig : {
maxHeight : 220
},
So this sends the AJAX call and show suggestions on typing the first letter. However, I want to show the suggestions when the combo is focused and even before the typing starts.
I could send out the AJAX call using the 'focus' listener. However, it doesn't show the suggestions.
listeners:{
'focus': function(){
this.store.load();
}
}
You can check if picker is created. If its created just show otherwise invoke trigger function.
Here is example :
Ext.application({
name: 'Fiddle',
launch: function () {
var states = Ext.create('Ext.data.Store', {
fields: ['abbr', 'name'],
proxy: {
type: 'ajax',
url: 'data.json',
reader: {
type: 'json'
}
},
autoLoad: true
});
Ext.create('Ext.panel.Panel', {
renderTo: Ext.getBody(),
title: 'combo example',
layout: 'fit',
items: [{
xtype: 'combobox',
fieldLabel: 'Choose State',
store: states,
queryMode: 'local',
displayField: 'name',
valueField: 'abbr',
listeners: {
focus: function (component) {
component.store.load(function () {
if (Ext.isEmpty(component.picker)) {
component.onTriggerClick();
} else {
component.picker.show();
}
});
}
}
}]
});
}
});
Example Fiddle: https://fiddle.sencha.com/#view/editor&fiddle/2a04

How to search item with keyboard letter key in extjs combobox? 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

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.

Categories