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

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

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

fieldset set value dynamically sencha touch 2.2

i am new for sencha touch. Please see code at below
view.js
Ext.define("blackbutton.view.Setup.UserProfile", {
requires: [
'Ext.form.*',
'Ext.form.Panel',
'Ext.form.FieldSet',
'Ext.field.Number',
'Ext.field.Spinner',
'Ext.field.Password',
'Ext.field.Email',
'Ext.field.Url',
'Ext.field.DatePicker',
'Ext.field.Select',
'Ext.field.Hidden',
'Ext.field.Radio',
'Ext.field.Slider',
'Ext.field.Toggle'
],
extend: 'Ext.form.Panel',
xtype: 'SetupUserProfile',
id: 'SetupUserProfile',
config: {
//floating: true,
//centered: true,
cls: 'bb-popupForm',
modal: true,
width: "100%",
layout: 'fit',
height: "100%",
styleHtmlContent: true,
//title: 'Black Button',
//iconCls: 'black',
scrollable: true,
items: [{
docked: 'top',
xtype: 'titlebar',
title: 'Profile',
items: [{
xtype: 'button',
iconMask: true,
iconCls: 'reply',
//text: 'Back',
handler: function () {
//Code here??
}
}]
},
{
xtype: 'panel',
layout: 'vbox',
scrollable: true,
items: [{
xtype: 'fieldset',
id:'SetupUserProfileFS',
title: 'Personal Info',
instructions: 'Please enter the information above',
defaults: {
labelWidth: '35%',
required: true
},
items: [
{
xtype: 'textfield',
id: 'BB_ID',
name: 'BB_ID',
label: 'BB ID',
},
{
xtype: 'emailfield',
id: 'email',
name: 'email',
label: 'Email',
placeHolder: 'me#email.com',
}, {
xtype: 'textfield',
id: 'fullName',
name: 'fullName',
label: 'Full Name',
placeHolder: 'John',
}, {
xtype: 'numberfield',
id: 'mobilePhone',
name: 'mobilePhone',
label: 'Mobile Phone',
placeHolder: '012567890',
},
{
xtype: 'textfield',
id: 'DOB',
name: 'DOB',
label: 'Date of birth',
placeHolder: '30/03/1988',
},
{
xtype: 'textfield',
id: 'mailingAddress',
name: 'mailingAddress',
label: 'Mailing Address',
placeHolder: 'No 11, Jalan taman desa, 54100 KL',
}
]
},
}]
}]
}]
}
});
I need to change fieldset value when I press Reply button. Any example? please give me solution. Thanks
In your Handler you want to dynamically set the values for you fieldset. So the handler for your button would look something like this:
...
items: [
{
xtype: 'button',
iconMask: true,
iconCls: 'reply',
handler: function () {
Ext.getCmp('BB_ID').setValue('New value for BB_ID field');
Ext.getCmp('email').setValue('New value for email field');
Ext.getCmp('fullName').setValue('New value for fullName field');
Ext.getCmp('mobilePhone').setValue('New value for mobilePhone field');
Ext.getCmp('DOB').setValue('New value for DOB field');
Ext.getCmp('mailingAddress').setValue('New value for mailingAddress field');
}
}
]
...

Change form panel title sencha touch

I need to change my title inside a formpanel
Here is my code
view.js
Ext.define('bluebutton.view.BlueButton.Loyalty', {
extend: 'Ext.Container',
xtype: 'loyaltycard',
requires: [
'bluebutton.view.BlueButton.TransactionList',
'bluebutton.view.BlueButton.MemberPopUp',
'bluebutton.view.BlueButton.MemberDetail',
'bluebutton.view.BlueButton.CouponMain',
'bluebutton.store.BlueButton.MemberList',
'bluebutton.store.BlueButton.CouponList',
'Ext.ux.keypad.Keypad',
'Ext.Img',
'Ext.carousel.Carousel'
],
config: {
// iconCls: 'add_black',
// title :'Loyalty Point',
styleHtmlContent: true,
cls: 'styledContent',
//
layout: 'hbox',
border: 3,
ui: 'round',
defaults: {
margin : '10 10 10 10',
padding : 10
},
items :[
{
flex: 1,
xtype :'formpanel',
id:'loyaltyform',
items :[
{
xtype: 'fieldset',
cls :'containerRadious' ,
title: 'Welcome, new member ~<i><u>Kenny</u></i>',
defaults: {
labelWidth: '35%',
style: 'font-size:1.0em'
},
items: [
{
xtype: 'image',
src: 'resources/images/user3.png',
height: 100,
margin:20
},
{
xtype: 'textfield',
name : 'Name',
label: 'Name',
value :'Kenny Chow',
readOnly: true
},
{
xtype: 'textfield',
name : 'Age',
label: 'Age',
value :'20',
readOnly: true
},
{
xtype: 'textfield',
name : 'Point',
label: 'Point Available',
value :'50',
id :'point',
readOnly: true
},
{
xtype: 'textfield',
name : 'lastVisited',
label: 'Last Visited',
id :'lastVisited',
value :'27/12/2012 11:53 AM',
readOnly: true
},
{
xtype:'button',
text: 'Scan',
width : '100%',
id: 'btnScan',
},
]
}
]
},
{
flex: 2,
xtype :'carousel',
cls :'containerRadious' ,
items :[
{
xtype :'keypad',
layout: {
type: 'hbox',
pack: 'center'
},
},
{
xtype:'couponlistcard'
}
]
}
],
}
});
Controller
onbtnAddClick: function (e) {
var loyaltyform = Ext.getCmp('loyaltyform');
var pointAvalaible = Ext.getCmp('point').getValue();
var keyPadValue = Ext.getCmp('keypad_value').getValue();
var consumerID = Ext.getCmp('keypad_value').getValue();
Ext.getCmp('loyaltyform').setTitle('Changed Title');;
}
but i get this error.
**Uncaught TypeError: Object [object Object] has no method 'setTitle'**
Anyone face this problem before? please help
The reason you get the error is because a formpanel has no method setTitle(). To change the title you have to call the setTitle() method of your fieldset, which is inside your formpanel. So give you fieldset an ID and use this:
Ext.getCmp('yourFieldsetID').setTitle('Changed Title');
Check the methods you can use for a panel en fieldset in the Sencha docs:
http://docs.sencha.com/touch/2-1/#!/api/Ext.form.Panel
http://docs.sencha.com/touch/2-1/#!/api/Ext.form.FieldSet
Good luck!

I can't group a list

Ext.define('MyApp.view.MyPanel', {
extend: 'Ext.Panel',
xtype:'mypanel',
config: {
ui: 'dark',
layout: {
type: 'card'
},
items: [
{
xtype: 'titlebar',
docked: 'top',
title: 'Lezzet Dunyasi',
items: [
{
xtype: 'button',
docked: 'right',
height: 29,
hidden: true,
ui: 'back',
text: 'back'
}
]
},
{
xtype: 'list',
docked: 'left',
id: 'mylist',
ui: 'round',
grouped:true,
pinHeaders:false,
width: 331,
itemTpl: [
'<img src="{img_url}" width="60" heigh="60"></img><span>{label}</span>'
],
store: 'Menius',
items: [
{
xtype: 'searchfield',
docked: 'top',
placeHolder: 'Search...',
}
]
},
{
xtype: 'panel',
styleHtmlContent:true,
style: {
backgroundImage: 'url(resources/img/Landscape.png)',
backgroundRepeat: 'no-repeat',
backgroundPosition: 'center'
},
id:'mypanel'
}
]
}
});
My Store
I use some codes in my store
sorters:'id',
grouper:function(record) {
return record.get('id')[4];
When i write grouped:true into the list config , app doesn't run. I don't understand the reason.
I want to see same result like kitchensink example userinterface/list/disclosure section.
add this configartion in your store
groupField:'label'

Ext.getCmp("myForm") is undefined issue

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.