Ext js migration from 3 to 4 - ComboBox crashes application - extjs

I am migrating Ext js from 3.x to the new 4.0.2a. Seems that everything in my project works fine except of comboboxes. It doesn't really matter where i use a combobox, but it keeps crashing my application on launch.
the error im getting is: Uncaught RangeError: Maximum call stack size exceeded
Here is an example of my code (login page with combobox):
index.html:
<link rel="stylesheet" type="text/css" href="resources/css/ext-all.css" />
<script type="text/javascript" src="ext-all-debug.js"></script>
<script type="text/javascript" src="ext3-core-compat.js"></script>
<script type="text/javascript" src="ext3-compat.js"></script>
<script type="text/javascript" src="js/app.js"></script>
<script type="text/javascript" src="js/My.Viewport.js"></script>
<script type="text/javascript" src="js/My.LoginWindow.js"></script>
app.js:
Ext.BLANK_IMAGE_URL = '/ext/resources/images/default/s.gif';
Ext.ns('My');
My.Base = function (){
Ext.QuickTips.init();
return {
init: function () {
var win = Ext.create('My.LoginWindow',{
title: 'Authorization',
callback: function(){
new Dag.Viewport();
}
});
win.show();
}
}
}();
Ext.onReady(My.Base.init, My.Base);
My.LoginWindow.js:
Ext.define('My.LoginWindow', {
extend:'Ext.Window',
//alias: 'widget.LoginWindow', This is not required.
initComponent: function(){
Ext.define('test', {
extend: 'Ext.data.Model',
fields: ['abbr', 'name']
});
var states = Ext.create('Ext.data.Store', {
model: 'test',
data : [
{"abbr":"AL", "name":"Alabama"},
{"abbr":"AK", "name":"Alaska"},
{"abbr":"AZ", "name":"Arizona"}
]
});
this.form = Ext.create('Ext.form.Panel',{
baseCls: 'x-plain',
defaultType: 'textfield',
defaults: {
labelWidth: 55,
allowBlank: false,
anchor:'100%'
},
items: [{
xtype: 'combobox',
fieldLabel: 'Choose State',
store: states,
queryMode: 'local',
displayField: 'name',
valueField: 'abbr'
},{
fieldLabel: 'Account',
name: 'account'
},{
fieldLabel: 'Login',
name: 'login'
},{
fieldLabel: 'Password',
name: 'password',
inputType: 'password',
listeners: {
'specialkey': function(field, e){
if (e.getKey() == 13){
this.submitForm();
}
},
scope: this
}
}]
});
Ext.apply(this, {
modal: true,
resizable: false,
closable: false,
plain: true,
width: 200,
draggable: false,
bodyStyle:'padding:5px;',
items: this.form,
buttons: [{
text: 'Login',
handler: this.submitForm,
scope: this
},{
text: 'Cancel',
handler: function(){
this.form.getForm().reset();
},
scope: this
}]
});
this.callParent(arguments);
},
submitForm: function(){
var f = this.form.getForm();
f.submit({
url: 'myurl',
waitMsg: 'Login...',
waitTitle: 'Wait',
scope: this,
success: function(form, action){
this.callback.call();
this.close();
},
failure: function(form, action){
var res = action.result;
var msg = 'Enter correct login and password, please.'
if (res && res.message){
msg = res.message;
}
Ext.Msg.alert('Error', msg);
}
});
}
});
As you can see im using a standard combobox with standard data (from sencha's example docs).
When i now launch the application, it crashes with the error message described above.
But when i remove the combobox, the application fully works, i see the login window and can login to show the My.Viewport.
What can cause this error, does some code call itself all the time? I've spend many hours fixing this annoying problem, but no luck so far.
Thanks for your help in advance.

I do see some things you still need to update, for example switching the superclass call with callParent, replacing the new X() calls with Ext.create(), etc. However, nothing jumps out at me that would be causing a stack overflow. You should probably break on errors in Firebug and do a little debugging to see where the issue is originating.

Related

Plant.js file not found when using an example from Sencha Docs website

I am having an error when I use an example from the Sencha Docs website. The example is a grid which you can find here
So I tried to copy all the code, but for some reason it does not work for me.
app.js
const test = Ext.define('KitchenSink.view.grid.CellEditing', {
extend: 'Ext.grid.Panel',
requires: [
'Ext.selection.CellModel',
'Ext.grid.*',
'Ext.data.*',
'Ext.util.*',
'Ext.form.*',
'KitchenSink.model.grid.Plant'
],
xtype: 'cell-editing',
title: 'Edit Plants',
frame: true,
initComponent: function() {
this.cellEditing = new Ext.grid.plugin.CellEditing({
clicksToEdit: 1
});
Ext.apply(this, {
width: 680,
height: 350,
plugins: [this.cellEditing],
store: new Ext.data.Store({
// destroy the store if the grid is destroyed
autoDestroy: true,
model: KitchenSink.model.grid.Plant,
proxy: {
type: 'ajax',
// load remote data using HTTP
url: 'resources/data/grid/plants.xml',
// specify a XmlReader (coincides with the XML format of the returned data)
reader: {
type: 'xml',
// records will have a 'plant' tag
record: 'plant'
}
},
sorters: [{
property: 'common',
direction:'ASC'
}]
}),
columns: [{
header: 'Common Name',
dataIndex: 'common',
flex: 1,
editor: {
allowBlank: false
}
}, {
header: 'Light',
dataIndex: 'light',
width: 130,
editor: new Ext.form.field.ComboBox({
typeAhead: true,
triggerAction: 'all',
store: [
['Shade','Shade'],
['Mostly Shady','Mostly Shady'],
['Sun or Shade','Sun or Shade'],
['Mostly Sunny','Mostly Sunny'],
['Sunny','Sunny']
]
})
}, {
header: 'Price',
dataIndex: 'price',
width: 70,
align: 'right',
renderer: 'usMoney',
editor: {
xtype: 'numberfield',
allowBlank: false,
minValue: 0,
maxValue: 100000
}
}, {
header: 'Available',
dataIndex: 'availDate',
width: 95,
renderer: Ext.util.Format.dateRenderer('M d, Y'),
editor: {
xtype: 'datefield',
format: 'm/d/y',
minValue: '01/01/06',
disabledDays: [0, 6],
disabledDaysText: 'Plants are not available on the weekends'
}
}, {
xtype: 'checkcolumn',
header: 'Indoor?',
dataIndex: 'indoor',
width: 90,
stopSelection: false
}, {
xtype: 'actioncolumn',
width: 30,
sortable: false,
menuDisabled: true,
items: [{
icon: 'resources/images/icons/fam/delete.gif',
tooltip: 'Delete Plant',
scope: this,
handler: this.onRemoveClick
}]
}],
selModel: {
selType: 'cellmodel'
},
tbar: [{
text: 'Add Plant',
scope: this,
handler: this.onAddClick
}]
});
this.callParent();
this.on('afterlayout', this.loadStore, this, {
delay: 1,
single: true
})
},
loadStore: function() {
this.getStore().load({
// store loading is asynchronous, use a load listener or callback to handle results
callback: this.onStoreLoad
});
},
onStoreLoad: function(){
Ext.Msg.show({
title: 'Store Load Callback',
msg: 'store was loaded, data available for processing',
icon: Ext.Msg.INFO,
buttons: Ext.Msg.OK
});
},
onAddClick: function(){
// Create a model instance
var rec = new KitchenSink.model.grid.Plant({
common: 'New Plant 1',
light: 'Mostly Shady',
price: 0,
availDate: Ext.Date.clearTime(new Date()),
indoor: false
});
this.getStore().insert(0, rec);
this.cellEditing.startEditByPosition({
row: 0,
column: 0
});
},
onRemoveClick: function(grid, rowIndex){
this.getStore().removeAt(rowIndex);
}
})
Ext.application({
name: 'MyApp',
launch: function() {
Ext.create('Ext.container.Viewport', {
items: [{
items: test
}]
})
}
})
index.html:
<html>
<head>
<!-- <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> -->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- <link rel='shortcut icon' href='./imatges/icones/petits/login.png' type='image/png'> -->
<title>Sencha</title>
<!-- CDN 4.2.1- NEPTUNE -->
<link href="http://cdn.sencha.io/ext/gpl/4.2.1/resources/css/ext-all-neptune.css" rel="stylesheet" />
<script src="http://cdn.sencha.com/ext/gpl/4.2.1/ext-all.js"></script>
<link href="http://cdn.sencha.io/ext/gpl/4.2.1/resources/css/ext-all-neptune.css" rel="stylesheet" />
<!-- JScript -->
<script type="text/javascript" src="app.js"></script>
</head>
<body>
</body>
</html>
I keep getting this error when I open it on the browser:
Why is it not working and how to solve this?
Thanks
You're defining the CellEditing and model.grid.Plant with the app name of KitchenSink:
const test = Ext.define('KitchenSink.view.grid.CellEditing',{
//rest of your code
requires: [
//other requires
'KitchenSink.model.grid.Plant'
]
store: new Ext.data.Store({
// destroy the store if the grid is destroyed
autoDestroy: true,
model: KitchenSink.model.grid.Plant,
//rest of store
onAddClick: function(){
// Create a model instance
var rec = new KitchenSink.model.grid.Plant({
//rest of model configs
But in the Ext.application, you define the name of the application as "MyApp":
Ext.application({
name: 'MyApp',
//other configs
Change the name of the application to KitchenSink or define the CellEditing, the requires and the models like:
const test = Ext.define('MyApp.view.grid.CellEditing',{
//rest of your code
And see if it works.

Extjs 4.2 returns " NetworkError: 404 Not Found " error

I am new to extjs.I tried to write a simple application with MVC architecture as described here :
http://docs-origin.sencha.com/extjs/4.2.1
When I try to run the application in browser I give this error in firebug:
"NetworkError: 404 Not Found - http://127.0.0.1/Sample/app/view/userlist.js?_dc=1408194279243"
My project structured is :
List.js file :
/**
* Created by Sina-PC on 8/14/14.
*/
Ext.define('Sample.view.users.List' ,{
extend: 'Ext.grid.Panel',
alias: 'widget.userlist',
title: 'All Users',
initComponent: function() {
this.store = {
fields: ['name', 'email'],
data : [
{name: 'Ed', email: 'ed#sencha.com'},
{name: 'Tommy', email: 'tommy#sencha.com'}
]
};
this.columns = [
{header: 'Name', dataIndex: 'name', flex: 1},
{header: 'Email', dataIndex: 'email', flex: 1}
];
this.callParent(arguments);
}
});
Users.js file:
Ext.define('Sample.controller.Users', {
extend: 'Ext.app.Controller',
views:['userlist'],
init: function() {
console.log('Initzed Users! This happens before the Application launch function is called');
this.control({
'viewport > panel': {
render: this.onPanelRendered
}
});
}
,
onPanelRendered: function() {
console.log('The panel was rendered');
}
});/**
* Created by Sina-PC on 8/14/14.
*/
app.js file :
Ext.application({
name: 'Sample',
appFolder:'app',
controllers:[
'Users'
],
launch: function() {
Ext.create('Ext.container.Viewport', {
layout: 'fit',
items: [
{
xtype: 'userlist'
}
]
});
}
});
and index.html:
<html>
<head>
<title>Hello Ext</title>
<link rel="stylesheet" type="text/css" href="extjs/resources/css/ext-all.css">
<script type="text/javascript" src="extjs/ext-all-debug.js"></script>
<script type="text/javascript" src="app.js"></script>
</head>
<body></body>
</html>
ExtJs doesn't know what is a view 'userlist'. You must add to requires this file.
Ext.define('Sample.controller.Users', {
requires: [ 'Sample.view.users.List' ],
...
Users.js file has "views:['userlist']," and it should be "views:['Sample.view.users.List'],"

How to Make my Label as the Hyperlink in Sencha EXT JS

Can any one please help to make my label as hyperlink in Sencha EXT JS.
You can just tell the fieldLabel to be a link http://jsfiddle.net/EsppR/1/
Ext.create('Ext.form.Panel', {
title: 'Contact Info',
renderTo: Ext.getBody(),
items: {
xtype: 'textfield',
name: 'name',
fieldLabel: 'Name',
allowBlank: false // requires a non-empty value
}
});
Here is a solution of your problem: [hyperlink in Sencha EXT JS]: how to create hyper link in extjs4?
or you can add new event for your label:
Ext.onReady(function() {
var yourLabel = new Ext.form.Label({
id:'yourLabel',
text: 'http://your-link-here.com',
renderTo : document.body
});
Ext.getCmp('yourLabel').getEl().on('click',function(){
window.open("http://your-link-here.com");
});
});
As a plugin:
Ext.define('YourCompany.plugins.LinkedLabel', {
extend: 'Ext.AbstractPlugin',
url: undefined,
init: function (cmp) {
this.setCmp(cmp);
cmp.beforeLabelTextTpl = '<a href="' + url + '">';
cmp.afterLabelTextTpl = '</a>';
});
});
Use:
{
xtype: 'textfield',
fieldLabel: 'Linked label',
plugins: Ext.create('YourCompany.plugins.LinkedLabel', { url: '/yourUrl' })
}
Two ways:
//1st - set html for label
{
xtype: "label",
html: "bla bla?! <a href='http:/\tiny.cc/snir' target='_blank'>Press This Link!!!</a><br>"
},
//2nd - create a new component
{
xtype: 'component',
autoEl: {
tag: 'a',
href: 'http:\/tiny.cc/snir/',
target: '_blank',
html: 'tiny.cc/snir'
}
}
You can see my example here https://fiddle.sencha.com/#view/editor&fiddle/1kqh and inspect the differents.

ExtJs 4.2.0.663 using Searchfield results in Exception "PageMap asked for range which it does not have"

because ExtJS 4.2 seems to have a bug in using filters on an buffered grid (infinite grid), i rewrote my code and now i'm just using a simple search field to let the user search all over the grid's data.
as long as something is found it works perfect but if nothing's found ext crashes with the exception
"Page Map asked for range which it does not have"
my javascript "includes"
<script type="text/javascript" src="/js/ext-4.2.0.663/examples/ux/grid/filter/Filter.js"></script>
<script type="text/javascript" src="/js/ext-4.2.0.663/examples/ux/grid/filter/BooleanFilter.js"></script>
<script type="text/javascript" src="/js/ext-4.2.0.663/examples/ux/grid/filter/DateFilter.js"></script>
<script type="text/javascript" src="/js/ext-4.2.0.663/examples/ux/grid/filter/ListFilter.js"></script>
<script type="text/javascript" src="/js/ext-4.2.0.663/examples/ux/grid/filter/NumericFilter.js"></script>
<script type="text/javascript" src="/js/ext-4.2.0.663/examples/ux/grid/filter/StringFilter.js"></script>
<script type="text/javascript" src="/js/ext-4.2.0.663/examples/ux/grid/menu/ListMenu.js"></script>
<script type="text/javascript" src="/js/ext-4.2.0.663/examples/ux/grid/menu/RangeMenu.js"></script>
<script type="text/javascript" src="/js/ext-4.2.0.663/examples/ux/grid/FiltersFeature.js"></script>
<script type="text/javascript" src="/js/ext-4.2.0.663/examples/ux/grid/TransformGrid.js"></script>
<script type="text/javascript" src="/ASDB4/js/ext-4.2.0.663/examples/ux/form/SearchField.js"></script>
my store:
this._store = Ext.create('Ext.data.Store', {
storeId: 'ActivityLogStore',
model: 'ActivityLogModel',
remoteGroup: true,
autoDestroy: true,
buffered: true,
remoteSort: true,
leadingBufferZone: 300,
pageSize: 100,
autoLoad: true,
proxy: {
type: 'ajax',
url: '~myurl~',
reader: {
root: 'data[0].sActivityLogsArr',
totalProperty: 'data[0].totalcount'
},
simpleSortMode: true,
simpleGroupMode: true,
groupParam: 'sort',
groupDirectionParam: 'dir',
filterParam: 'searchString',
encodeFilters: function (filters) {
return filters[0].value;
}
},
listeners: {
// This particular service cannot sort on more than one field, so if grouped, disable sorting
groupchange: function (store, groupers) {
var sortable = !store.isGrouped(),
headers = grid.headerCt.getVisibleGridColumns(),
i, len = headers.length;
for (i = 0; i < len; i++) {
headers[i].sortable = (headers[i].sortable !== undefined) ? headers[i].sortable : sortable;
}
},
beforeload: function () {
// remove any selections - otherwise store loading crashes (another bug in extjs ...?)
Ext.getCmp('activityLogmanagergrid').getSelectionModel().clearSelections();
},
// This particular service cannot sort on more than one field, so if grouped, disable sorting
beforeprefetch: function (store, operation) {
if (operation.groupers && operation.groupers.length) {
delete operation.sorters;
}
},
load: function () {
Ext.getCmp('activityLogmanagergrid').verticalScroller.scrollTo(0);
}
}
});
my searchfield, located at the toolbar:
this._moduleToolbar = {
xtype: 'toolbar',
itemId: 'activityLogmanagerToolbar',
items: [{
iconCls: 'icon-arrow_refresh',
text: '#menu_reload#',
itemId: 'btnReload',
scope: this,
handler: function () {
// reset list display to top to avoid corrupted display
Ext.getCmp('activityLogmanagergrid').store.load();
}
}, {
iconCls: 'icon-cross',
text: '#menu_deleteAllActivityLog#',
itemId: 'btnDeleteAll',
scope: this,
handler: this.DeleteAllActivityLog
}, '->', {
width: 300,
fieldLabel: 'Search',
labelWidth: 50,
xtype: 'searchfield',
store: scope._store
}
]
};
please help ...
I also had this problem. I posted to their forum (like others) and opened a support ticket. They did not come up with a solution for Ext JS 4.2, but the bug (and many others in buffered stores) got fixed in version 4.2.1. I think the nearly rebuilded most of the code there, so they did not have the option to make a cheap hotfix to 4.2.
Until I can migrate to 4.2.1 I wrapped all my find-record-calls with try-catch blocks. I also tried to override the getRange function in Store.js on line 3383, but it belongs to the internal PageMap class, so this is no option.

pre-selecting value from dropdown (Combo box) in extjs?

I have a combo box which displays item quantity. Based on item quantity selection i am displaying price value of the item. By default i am setting price value to first item value. However when i load the page, i want my combo box to display first item qty i.e 100.
Problem: it should load Qty : 100 rather loading blank
So i have a store defined as
Store = new Ext.data.JsonStore({
storeId: 'Store',
root: 'storevalue',
autoLoad: false,
baseParams: { itemid: '${itemID!""}',
adjustPrice: '${adjustPrice}',
overrideShowPrice: '${overrideShowPrice}' },
url: 'ListQtyPrice.epm',
fields: [ 'qty', 'rawprice', 'displayPrice' ]
});
Combo box to display Qty
<#if Select>
new DBEComboBox({
name: 'orderqty',
displayField: 'qty',
valueField: 'qty',
id: 'order-qty',
store: Store,
forceSelection: true,
mode: 'remote',
triggerAction: 'all',
allowBlank: true,
listWidth: 202,
triggerClass: 'orderqty-trigger',
width: 200
,defaultValue: 100
,listeners: {
// for price adjustments
}
});
</#if>
Store.load({
callback: function() {
alert("reached");
Ext.getCmp('order-qty').setValue(Store.getAt(0).get('qty'));
var oqc = Ext.getCmp('order-qty');
var value = Ext.getCmp('order-qty').getValue();
alert(" hey :" +value);
}
});
Able to see hey: 100 in alert statements
I've run into this problem a couple times. The only way I've actually gotten this resolved was to call setValue on the combobox after the store has loaded, you could just add a listener on the store, but that always seemed somewhat messy to me. I usually have a stand-alone event listener like this:
Store.on('load',function(store) {
Ext.getCmp('order-qty').setValue(store.getAt('0').get('qty'));
});
EDIT: 18 Jan 2012
OK as mentioned here is a complete working example of ComboBox with a default value being set. This is done using ExtJS 4.02, should work fine with 4.07 though, not sure about 4.1.
Make sure you put your correct extjs path in the links (see brackets at the top of html), otherwise just put both combo-example and data.json at the same directory level and they should run fine:
data.json:
[
{"value":1,"name":"Option 1"},
{"value":2,"name":"Option 2"},
{"value":3,"name":"Option 3"}
]
combo-example.html:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Combo Box Example</title>
<link rel="stylesheet" type="text/css" href="[your extjs path]/resources/css/ext-all.css">
<script type="text/javascript" src="[your extjs path]/ext-all.js"></script>
<script type="text/javascript" >
Ext.onReady(function() {
// the datastore
var myStore = new Ext.data.Store({
fields: ['value', 'name'],
proxy: {
type: 'ajax',
url : 'data.json',
reader: {
type: 'json'
}
},
autoLoad: true
});
// a window to hold the combobox inside of a form
myWindow = Ext.create('Ext.Window', {
title: 'A Simple Window',
width: 300,
constrain: true,
modal: true,
layout: 'fit',
items: [{
// the form to hold the combobox
xtype: 'form',
border: false,
fieldDefaults: {
labelWidth: 75
},
bodyPadding: '15 10 10 10',
items: [{
// the combobox
xtype: 'combo',
id: 'myCombo',
fieldLabel: 'A Label',
valueField: 'value',
displayField: 'name',
store: myStore,
//queryMode: 'local',
typeAhead: true,
forceSelection: true,
allowBlank: false,
anchor: '100%'
},{
// shows the selected value when pressed
xtype: 'button',
margin: '10 0 0 100',
text: 'OK',
handler: function() {
alert('Name: ' + Ext.getCmp('myCombo').getRawValue() +
'\nValue: ' + Ext.getCmp('myCombo').value);
}
}]
}]
});
// show the window
myWindow.show();
// function to give the combobox a default value
myStore.on('load',function(store) {
Ext.getCmp('myCombo').setValue(store.getAt('0').get('value'));
});
});
</script>
</head>
<body>
</body>
</html>

Resources