Ext.getCmp("myForm") is undefined issue - extjs4

In one of my panels i have a form panel
xtype: 'form',
id: 'formJobSummary',
layout: {
align: 'stretch',
type: 'hbox'
}
I wish to bind data to this and have the following code.
var form = Ext.getCmp('formJobSummary').getForm();
form.loadRecord(user);
I am getting:
Ext.getCmp("formJobSummary") is undefined
So obviously the loadRecord is out of scope. Given that my architecture is from the designer and has 2 files. Where do i put this loadRecord statement.
MyPanel.js
//Define a model with field names mapping to the form field name
Ext.define('UserModel', {
extend: 'Ext.data.Model',
fields: ['quotedPrice', 'name']
});
//Create an instance of the model with the specific value
var user = Ext.create('UserModel', {
quotedPrice: 'test',
name: 'test'
});
Ext.define('MyApp.view.MyPanel', {
extend: 'MyApp.view.ui.MyPanel',
initComponent: function () {
var me = this;
me.callParent(arguments);
me.down('button[text=Submit]').on('click',
me.onSubmitBtnClick, me);
me.down('button[text=Cancel]').on('click',
me.onCancelBtnClick, me);
},
onSubmitBtnClick: function () {
var conn = new Ext.data.Connection();
var est = Ext.getCmp('estimate');
alert(est.getValue());
conn.request({
method: 'POST',
url: 'tmp.php',
params: {
foo: "bar"
},
success: function (responseObject) { alert(responseObject.responseText); },
failure: function () { alert(est); }
});
},
onCancelBtnClick: function () {
}
});
var form = Ext.getCmp('formJobSummary').getForm(); //returns form1
form.loadRecord(user);
ui/MyPanel.js
Ext.define('MyApp.view.ui.MyPanel', {
extend: 'Ext.panel.Panel',
height: 600,
width: 950,
layout: {
align: 'stretch',
type: 'vbox'
},
title: 'JobPanel',
initComponent: function() {
var me = this;
Ext.applyIf(me, {
items: [
{
xtype: 'tabpanel',
activeTab: 0,
flex: 1,
items: [
{
xtype: 'panel',
layout: {
align: 'stretch',
type: 'hbox'
},
title: 'Job Summary',
items: [
{
xtype: 'form',
id: 'formJobSummary',
layout: {
align: 'stretch',
type: 'hbox'
},
bodyPadding: 10,
title: '',
url: '/submit.html',
flex: 1,
dockedItems: [
{
xtype: 'toolbar',
flex: 1,
dock: 'bottom',
items: [
{
xtype: 'button',
text: 'Submit'
},
{
xtype: 'button',
text: 'Cancel'
}
]
}
],
items: [
{
xtype: 'panel',
flex: 1,
items: [
{
xtype: 'radiogroup',
width: 400,
fieldLabel: 'Job Type',
items: [
{
xtype: 'radiofield',
boxLabel: 'Fix Price'
},
{
xtype: 'radiofield',
boxLabel: 'Production'
}
]
},
{
xtype: 'textfield',
id: 'quotedPrice',
name: 'quotedPrice',
fieldLabel: 'Quoted Price'
},
{
xtype: 'textfield',
id: 'clientPO',
name: 'clientPO',
fieldLabel: 'Client PO'
},
{
xtype: 'textfield',
id: 'jobQuantity',
name: 'jobQuantity',
fieldLabel: 'Job Quatity'
},
{
xtype: 'textfield',
id: 'filesOver',
name: 'filesOver',
fieldLabel: 'Files Over'
},
{
xtype: 'textfield',
id: 'previousJobId',
name: 'previousJobId',
fieldLabel: 'Previous JobId'
},
{
xtype: 'textfield',
id: 'estimate',
name: 'estimate',
fieldLabel: 'Estimate'
}
]
},
{
xtype: 'panel',
flex: 1
},
{
xtype: 'panel',
layout: {
align: 'stretch',
type: 'hbox'
},
flex: 1
}
]
}
]
},
{
xtype: 'panel',
title: 'Parts'
},
{
xtype: 'panel',
title: 'Process'
},
{
xtype: 'panel',
title: 'Invoice'
}
]
},
{
xtype: 'panel',
layout: {
align: 'stretch',
type: 'vbox'
},
title: 'FooterPanel',
flex: 1
}
]
});
me.callParent(arguments);
}
});

During the execution of your statement var form = Ext.getCmp('formJobSummary').getForm(); obviously the formJobSummary is undefined (ie, it doesn't exist!!). Your Ext.define doesn't create a instance of the view. The code you are trying to execute is on a global scope.. meaning it will get executed as soon as the javascript file is loaded. Ideally, It should get called after an instance of the class is created.
So, your solution will be identify, when you need to load your form with the data you have. For example, you might want to load the data when you render the form or when some button is clicked etc. That should help you solve the problem.

Related

FormPanel getValues() not working on button tap event in sencha touch2?

I’ve created a FormPanel form for submitting some record in our database.
FormPanel Code:
Ext.define('MyApp.view.NIForm', {
extend: 'Ext.form.Panel',
config: {
id: 'NIForm',
items: [
{
xtype: 'panel',
items: [
{
xtype: 'textfield',
docked: 'left',
id: 'ORDNUM_39',
width: '95%',
label: 'Order#',
name: 'ORDNUM_39'
},
{
xtype: 'button',
docked: 'right',
itemId: 'browseOrder',
width: '5%',
text: '...'
}
]
},
{
xtype: 'textfield',
id: 'DESC',
style: 'margin-top:2px;',
label: 'Description',
name: 'DESC'
},
{
xtype: 'numberfield',
id: 'TNXQTY_39',
style: 'margin-top:2px;',
label: 'Quantity',
name: 'TNXQTY_39'
},
{
xtype: 'panel',
items: [
{
xtype: 'textfield',
docked: 'left',
style: 'margin-top:2px;',
width: '95%',
label: 'GL Code',
name: 'GLREF_39'
},
{
xtype: 'button',
docked: 'right',
width: '5%',
text: '...'
}
]
},
{
xtype: 'textfield',
id: 'REFDSC_39',
style: 'margin-top:2px;',
label: 'Reference',
name: 'REFDSC_39'
},
{
xtype: 'button',
action: 'niProcess',
itemId: 'mybutton3',
style: 'margin-top:6px;',
ui: 'confirm',
text: 'Process'
}
],
listeners: [
{
fn: 'onBrowseOrderTap',
event: 'tap',
delegate: '#browseOrder'
}
]
}
});
Now I want to get all textfields value on process button tap event, To get the formpanel value I've written following line of code.
var me = this;
var form = this.getNIForm();
var values = form.getValues();
var record = form.getRecord();
Can you tell me what am I doing wrong? Please explain.
Added another listener and it seems to work fine.
listeners: [{
fn: function () {
console.info('sdfsd');
},
event: 'tap',
delegate: '#browseOrder'
}, {
fn: function () {
console.info(this.getValues());
},
event: 'tap',
delegate: '#mybutton3'
}]
Here is the fiddle
If you want to retrieve particular TextField value use
Ext.getCmp('ORDNUM_39').getValue();
To get all form field values u can use like,
var form = this.getNav();
//if ur ref name inside ur controller is nav

Changing Displayed Card In Sencha Touch From The Controller

Once I have signed in I want the sign in page to be replaced with the dashboard page but for some reason I can't get the card to change as I cant get a refrence to it that will accept the setActiveItem method.
app.js
Ext.Loader.setConfig({
enabled: true
});
Ext.application({
views: [
'MainPanel'
],
name: 'MyApp',
controllers: [
'MainController'
],
launch: function() {
Ext.create('MyApp.view.MainPanel', {fullscreen: true});
}
});
MainController.js
Ext.define('MyApp.controller.MainController', {
extend: 'Ext.app.Controller',
alias: 'controller.mainController',
config: {
},
init: function(application) {
this.control({
'button[action=submitSigninemEmail]': {
tap: 'signinemEmailFnc'
}
});
},
signinemEmailFnc: function() {
var email_fld = Ext.getCmp('signinemEmail').getValue();
var password_fld = Ext.getCmp('signinemPassword').getValue();
var md5password = MD5(password_fld);
Ext.data.JsonP.request({
url: 'http://www.solumac.co.uk/clients/uwana/v2/ajax/sencha.php',
params: {
method: 'signinem',
callback: 'signinem',
email: email_fld,
password: md5password
},
callback: function(result, params) {
if (result === true) {
if (params.status === true){
console.log('signed in');
MyApp.views.MainPanel.setActiveItem('dashboard', {type:'slide', direction:'left'});
} else {
console.log(params.message);
}
}
}
});
}
});
MainPanel.js
Ext.define('MyApp.view.MainPanel', {
extend: 'Ext.Panel',
alias: 'widget.mainPanel',
config: {
layout: {
type: 'card'
},
items: [
{
xtype: 'container',
id: 'signinem',
layout: {
type: 'fit'
},
items: [
{
xtype: 'titlebar',
docked: 'top',
id: 'signinemTitleBar',
title: 'Sign In',
items: [
{
xtype: 'button',
id: 'signinemButtonBack',
ui: 'back',
text: 'Back'
},
{
xtype: 'button',
align: 'right',
id: 'signinemButtonSignUp',
text: 'Sign Up'
}
]
},
{
xtype: 'container',
id: 'signinemPadding',
padding: 10,
width: '100%',
items: [
{
xtype: 'fieldset',
id: 'signinemFacebookSet',
title: 'Sign In with Facebook',
items: [
{
xtype: 'button',
id: 'signinemFacebook',
margin: 10,
width: '',
text: 'Facebook'
}
]
},
{
xtype: 'fieldset',
id: 'signinemEmailSet',
title: 'Sign In with Email',
items: [
{
xtype: 'textfield',
id: 'signinemEmail',
margin: 10,
label: 'email'
},
{
xtype: 'passwordfield',
id: 'signinemPassword',
margin: 10,
label: 'Password'
},
{
xtype: 'checkboxfield',
action: 'changeField',
id: 'signinemShow',
itemId: 'mycheckbox',
margin: 10,
label: 'show password',
labelWidth: '80%'
},
{
xtype: 'button',
action: 'submitSigninemEmail',
id: 'signinemSubmit',
margin: 10,
text: 'Submit'
}
]
}
]
}
]
},
{
xtype: 'container',
id: 'dashboard',
layout: {
type: 'fit'
},
items: [
{
xtype: 'titlebar',
docked: 'top',
id: 'dashboardBar',
title: 'Dashboard'
}
]
},
listeners: [
{
fn: 'onSigninemShowCheck',
event: 'check',
delegate: '#signinemShow'
},
{
fn: 'onSigninemShowUncheck',
event: 'uncheck',
delegate: '#signinemShow'
}
]
},
onSigninemShowCheck: function(checkboxfield, e, options) {
alert('show password');
},
onSigninemShowUncheck: function(checkboxfield, e, options) {
alert('hide password');
}
});
I believe the problem lies with the line...
MyApp.views.MainPanel.setActiveItem('dashboard', {type:'slide', direction:'left'});
...which doesn't work, but have drawn a complete blank as to what should replace it.
if you change
Ext.create('MyApp.view.MainPanel', {fullscreen: true});
to
Ext.Viewport.add(Ext.create('MyApp.view.MainPanel'));
in your app.js, then in your controller change
MyApp.views.MainPanel.setActiveItem('dashboard', {type:'slide', direction:'left'});
to
Ext.Viewport.setActiveItem(Ext.create('dashboard'),{
// other stuff
});
and add dashboard to your views array in app.js I believe it should work
You can't just do a setActiveItem of the id string like you did above:
MyApp.views.MainPanel.setActiveItem('dashboard', {type:'slide', direction:'left'});
You first have to get the reference to the component using Ext.getCmp().
Also, MyApp.views.MainPanel is a class name, and not an instance. You would need to get the specific instance object, and then use it to set the active item.
Here's some code that will work for you:
var mypanel = Ext.ComponentQuery('mainPanel')[0];
var active = Ext.getCmp('dashboard');
mypanel.setActiveItem(active, {type: 'slide', direction: 'left'});
I'm also including a 1 file application that does what you want:
Ext.define('MyApp.view.MyPanel', {
extend: 'Ext.Panel',
alias: 'widget.mypanel',
config: {
layout: {
type: 'card'
},
items: [
{
xtype: 'titlebar',
docked: 'top',
items: [
{
xtype: 'button',
handler: function(button, event) {
var comp = Ext.ComponentQuery.query('mypanel')[0];
var active = Ext.getCmp('c1');
comp.setActiveItem(active);
},
text: 'one'
},
{
xtype: 'button',
handler: function(button, event) {
var comp = Ext.ComponentQuery.query('mypanel')[0];
var active = Ext.getCmp('c2');
comp.setActiveItem(active);
},
text: 'two'
}
]
},
{
xtype: 'container',
html: 'Hello, first container',
id: 'c1'
},
{
xtype: 'container',
html: 'hello, second container',
id: 'c2'
}
]
}
});

Re-sizing form content to fit browser window - Using Card Layout

I need the tab-panels to fit browser window size. I have used card layout, and it is not re-sizing to fit the browser window. I think i'm missing some properties in my viewPort.
launch: function() {
Ext.create('Ext.container.Viewport', {
layout: 'card',
items: [
{
xtype: 'panel',
items: { xtype: 'tabP1' }
},
{
xtype: 'panel',
items: { xtype:'tabP2' }
}
,
{
xtype: 'panel',
items: { xtype:'tabP3' }
}
]
});
},
2.) One of my tabpanels; I am using absolute layout. I am using this layout because it's easy to set form components where i ever i desire it to be. Therefore, i would like a solution that works with the same layout.
Ext.define('MyApp.view.MyForm', {
extend: 'Ext.form.Panel',
alias:'widget.tabP1',
// height: 250,
// width: 726,
layout: {
type: 'absolute'
},
bodyPadding: 10,
title: 'My Form',
initComponent: function() {
var me = this;
Ext.applyIf(me, {
items: [
{
xtype: 'gridpanel',
title: 'My Grid Panel',
columns: [
{
xtype: 'gridcolumn',
dataIndex: 'string',
text: 'String'
},
{
xtype: 'numbercolumn',
dataIndex: 'number',
text: 'Number'
},
{
xtype: 'datecolumn',
dataIndex: 'date',
text: 'Date'
},
{
xtype: 'booleancolumn',
dataIndex: 'bool',
text: 'Boolean'
}
],
viewConfig: {
}
}
]
});
me.callParent(arguments);
}
});
UPDATE 2
UPDATE 2
launch: function() {
Ext.create('Ext.container.Viewport', {
layout: 'card',
items: [
{
xtype: 'tabP1'
},
{
xtype:'tabP2'
}
,
{
xtype:'tabP3'
}
]
});
},
onSuccess: function() {
this.getViewport().getLayout().setActiveItem(1);
},
I get an error when i use your code, saying that this.getViewport().getLayout().setActiveItem(1) is not a function. I think this is because i used border layout. How can i resolve this ?
Your problem is "over-nesting" Why are you putting 'tabPFoo' inside a panel with no layout? They are at best, redundant, also causing the layout system to spend more cycles when it's not needed.
Ext.require('*');
Ext.onReady(function(){
var vp = new Ext.container.Viewport({
layout: 'card',
items: [{
xtype: 'grid',
store: {
fields: ['name'],
data: [{
name: 'Name 1'
}]
},
columns: [{
flex: 1,
dataIndex: 'name',
text: 'Name'
}],
listeners: {
itemclick: function(view){
var grid = view.ownerCt,
next = grid.nextSibling();
vp.getLayout().setActiveItem(next);
}
}
}, {
xtype: 'grid',
store: {
fields: ['name'],
data: [{
name: 'Name 2'
}]
},
columns: [{
flex: 1,
dataIndex: 'name',
text: 'Name'
}],
listeners: {
itemclick: function(view){
var grid = view.ownerCt,
next = grid.nextSibling();
vp.getLayout().setActiveItem(next);
}
}
}, {
xtype: 'grid',
store: {
fields: ['name'],
data: [{
name: 'Name 3'
}]
},
columns: [{
flex: 1,
dataIndex: 'name',
text: 'Name'
}],
listeners: {
itemclick: function(view){
var grid = view.ownerCt,
next = grid.previousSibling().previousSibling();
vp.getLayout().setActiveItem(next);
}
}
}]
});
});
Obviously that's not MVC style, but that's the structure the layout should take.

Defining View in ExtJS. "Uncaught TypeError: Cannot call method 'substring' of undefined"

I am trying to define a view but I am getting an error
Uncaught TypeError: Cannot call method 'substring' of undefined
/app/view/Sidebar.js
Ext.define('SimpleTodo.view.Sidebar', {
extend: 'Ext.panel.Panel',
alias: 'widget.sidebar',
config: {
title: 'Projects & Todo Lists',
tbar: [
{
xtype: 'button',
text: 'Add Project'
},
{
xtype: 'button',
text: 'Add Todo List'
}
],
//store: Ext.data.StoreManager.lookup('projects'),
html: 'Hello world',
width: 200
}
});
Then tried to use it in my app.js
Ext.application({
name: 'SimpleTodo',
views: [
'Sidebar'
],
appFolder: 'app',
launch: function() {
Ext.create('Ext.container.Viewport', {
layout: {
type: 'hbox',
pack: 'start',
align: 'stretch'
},
items: [
{
xtype: 'sidebar' // <---- here
},
{
xtype: 'panel',
id: 'detailsView',
flex: 1,
layout: 'card',
items: [
{
xtype: 'panel',
id: 'todoDetails',
title: 'Todo Details'
},
{
xtype: 'panel',
id: 'addProject',
title: 'Add project',
}
]
}
]
})
}
});
What am I missing? Have I defined my views and used it correctly?
Actually it must be like that:
Ext.application({
name: 'SimpleTodo',
requires:[
'SimpleTodo.view.Sidebar'
],
appFolder: 'app',
launch: function() {
Ext.onReady(function(){
Ext.create('Ext.container.Viewport', {
layout: {
type: 'hbox',
pack: 'start',
align: 'stretch'
},
items: [
{
xtype: 'sidebar' // <---- here
},
{
xtype: 'panel',
id: 'detailsView',
flex: 1,
layout: 'card',
items: [
{
xtype: 'panel',
id: 'todoDetails',
title: 'Todo Details'
},
{
xtype: 'panel',
id: 'addProject',
title: 'Add project',
}
]
}
]
})
});
}
});

how to instantiate a formpanel when the form is a docked item in extjs

Very new to extjs 4.0. So i could be phrasing this incorrectly.
I have a layout with a series of nested panels. One of these panels is a form panel which i intend to use loadRecord to fill with data. Most examples i've seen using something like the following to load the records.
testForm.getForm().loadRecord(app.formStore);
However you will see below that my formpanel is nested. So how do i load the form in order to load record
title: 'Job Summary',
items: [
{
xtype: 'form',
id: 'formJobSummary',
layout: {
align: 'stretch',
type: 'hbox'
},
bodyPadding: 10,
title: '',
url: '/submit.html',
flex: 1,
dockedItems: [
{
xtype: 'toolbar',
flex: 1,
dock: 'bottom',
items: [
{
xtype: 'button',
text: 'Submit'
},
{
xtype: 'button',
text: 'Cancel'
}
]
}
],
items: [
{
xtype: 'panel',
flex: 1,
items: [
{
xtype: 'radiogroup',
width: 400,
fieldLabel: 'Job Type',
items: [
{
xtype: 'radiofield',
boxLabel: 'Fix Price'
},
{
xtype: 'radiofield',
boxLabel: 'Production'
}
]
},
{
xtype: 'textfield',
fieldLabel: 'Quoted Price'
},
{
xtype: 'textfield',
fieldLabel: 'Client PO'
},
{
xtype: 'textfield',
fieldLabel: 'Job Quatity'
},
{
xtype: 'textfield',
fieldLabel: 'Files Over'
},
{
xtype: 'textfield',
fieldLabel: 'Previous JobId'
},
{
xtype: 'textfield',
fieldLabel: 'Estimate'
}
]
},
{
xtype: 'panel',
flex: 1
},
{
xtype: 'panel',
layout: {
align: 'stretch',
type: 'hbox'
},
flex: 1
}
]
}
]
},
Here is the code which shows how to populate data in the formpanel:
Ext.onReady(function(){
//Define a model with field names mapping to the form field name
Ext.define('UserModel', {
extend: 'Ext.data.Model',
fields: ['first', 'last']
});
//Create an instance of the model with the specific value
var user = Ext.create('UserModel', {
first: 'Ajit',
last: 'Kumar'
});
var form = Ext.create('Ext.form.Panel', {
renderTo: Ext.getBody(),
title: 'Simple Form',
bodyPadding: 5,
width: 350,
layout: 'anchor',
defaults: {
anchor: '100%'
},
// The fields
defaultType: 'textfield',
items: [{
fieldLabel: 'First Name',
name: 'first', //this name must match with the field name in the model
allowBlank: false
},{
fieldLabel: 'Last Name',
name: 'last',
allowBlank: false
}],
// Reset and Submit buttons
buttons: [{
text: 'Reset',
handler: function() {
this.up('form').getForm().reset();
}
}, {
text: 'Submit',
formBind: true,
disabled: true,
handler: function() {
}
}]
});
form.loadRecord(user);
});
So, the steps are:
Define a model, which must extend Ext.data.Model as the stores and
form expect the date to be in the model format
Create a form panel
Create an instance of the model with the data
Load the data in the form using the model instance