How to pass parameter value from view to Ext.window? - extjs

I am get confused to pass value from view to window,
I have a view contain the user info and one button on which click a new window opens to upload an Image file. the image upload code I done in window. But I want to pass User Id with the image which I want to post on server. the user Id I on View. I want to carry that userId on file upload window. How can I do this?
Bellow is my code.
file upload view
Ext.define('vDemo.view.FileUpload', {
extend: 'Ext.Panel',
region: 'center',
border:'false',
initComponent: function () {
var me = this;
this.form = new Ext.form.Panel({
xtype: 'panel',
border: false,
//layout: 'vbox',
padding: '2 2 2 2',
bodyPadding: 10,
frame: false,
renderTo: Ext.getBody(),
items: [{
xtype: 'filefield',
name: 'photo',
fieldLabel: 'Photo',
labelWidth: 50,
msgTarget: 'side',
allowBlank: false,
anchor: '100%',
buttonText: 'Select Photo...'
}],
buttons: [{
text: 'Upload',
handler: function () {
var form = this.up('form').getForm();
if (form.isValid()) {
form.submit({
url: 'photo-upload.php',
waitMsg: 'Uploading your photo...',
success: function (fp, o) {
Ext.Msg.alert('Success', 'Your photo "' + o.result.file + '" has been uploaded.');
}
});
}
}
}]
});
this.items = [this.form];
this.callParent();
}
});
UserForm view (on which button click I am open the file upload window)
Ext.define('vDemo.view.userHome', {
extend: 'Ext.Panel',
border: false,
Padding: '5 5 5 5',
title: 'Home',
initComponent: function () {
var me = this;
this.changingImage = Ext.create('Ext.Img', {
src:'', //'appRes/ProfilePic/ProfilePic1.png',
width: 150,
height: 170
});
this.image = new Ext.Container({
cls: 'img-block',
padding:'0 0 2 0',
items: [this.changingImage]
});
this.ImagePanel = new Ext.form.Panel({
padding: '5 5 5 5',
layout: 'vbox',
border: false,
items: [
this.image,
{
xtype: 'button',
text: 'Chage Image',
width: 150,
height: 30,
handler: function () {
me.fileUpload();
}
}
]
});
this.InfoPanel = new Ext.form.Panel({
padding: '5 5 5 5',
layout: 'vbox',
border: false,
items: [{
xtype: 'hidden',
name: 'hfUserAutoId'
},
{
xtype: 'displayfield',
fieldLabel: 'Name:',
name: 'lblName',
value: ''
},
{
xtype: 'displayfield',
fieldLabel: 'Email:',
name: 'lblEmail',
value: ''
},
{
xtype: 'displayfield',
fieldLabel: 'Date of Birth:',
name: 'lblDateOfBirth',
value: ''
},
{
xtype: 'displayfield',
fieldLabel: 'UserId',
name: 'lblUserId',
value: ''
},
{
xtype: 'displayfield',
fieldLabel: 'Gender',
name: 'lblGender',
value: ''
},
{
xtype: 'displayfield',
fieldLabel: 'Blood Group',
name: 'lblBloodGroup',
value: ''
},
{
xtype: 'displayfield',
fieldLabel: 'Hieght',
name: 'lblHieght',
value: ''
}]
});
this.form = new Ext.form.Panel({
padding: '10 100 10 100',
layout: 'hbox',
header: {
titlePosition: 0,
items: [{
xtype: 'button',
text: 'Back',
handler: function () {
me.fireEvent('getBack');
}
}]
},
items: [me.ImagePanel, this.InfoPanel]
});
this.items = [this.form];
this.callParent();
},
fillForm: function(sRec) {
var me = this;
console.log(sRec);
// var sRec1 = Ext.StoreMgr.lookup('UserInfo').getById(ssRec.get('userAutoId'));
console.log(sRec[0].userAutoId);
me.form.getForm().findField('hfUserAutoId').setValue(sRec.userAutoId);
me.form.getForm().findField('lblName').setValue(sRec[0].firstName + " " + sRec[0].lastName);
me.form.getForm().findField('lblUserId').setValue(sRec[0].userid);
me.form.getForm().findField('lblEmail').setValue(sRec[0].email);
if (sRec[0].gender == true) {
me.form.getForm().findField('lblGender').setValue("Male");
}
else if (sRec[0].gender == false) {
me.form.getForm().findField('gender').setValue("Female");
};
me.form.getForm().findField('lblDateOfBirth').setValue(sRec[0].DOB);
me.form.getForm().findField('lblBloodGroup').setValue(sRec[0].bloodGroup);
me.form.getForm().findField('lblHieght').setValue(sRec[0].hieght);
// me.form.getForm().findField('image').setSrc(sRec.get('profilePicPath'));
me.changingImage.setSrc(sRec[0].profilePicPath);
},
fileUpload: function () {
this.uploadWinPanel = new vDemo.view.FileUpload({});
var hfUserAutoId = me.form.getForm().findField('hfUserAutoId').getValue();
this.EditWin = new Ext.Window({
//header:false,
Height: 400,
width: 320,
title: 'Upload Photo',
border: 0,
resizable: false,
draggable: false,
modal: false,
items: [this.uploadWinPanel]
}).show();
}
});

Well, you pass the user id on initialization of the uploadWinPanel like so:
var hfUserAutoId = me.form.getForm().findField('hfUserAutoId').getValue();
this.uploadWinPanel = new vDemo.view.FileUpload({
userId: hfUserAutoId
});
And then in the FileUpload component, beside the filefield, you add a hiddenfield which grabs the userId value:
items: [{
xtype: 'filefield',
name: 'photo',
fieldLabel: 'Photo',
labelWidth: 50,
msgTarget: 'side',
allowBlank: false,
anchor: '100%',
buttonText: 'Select Photo...'
},{
xtype: 'hiddenfield',
name: 'user_id',
value: this.userId
}]

Related

Extjs Ext.form.field.Tag, resize event is not fired

The resize event of tagfield is not fired after resize the panel in which tagfield is created.
Here is some part of code
Ext.application({
name: 'Fiddle',
launch: function () {
var shows = Ext.create('Ext.data.Store', {
fields: ['id', 'show'],
data: [{
id: 0,
show: 'Battlestar Galactica'
}, {
id: 1,
show: 'Doctor Who'
}, {
id: 2,
show: 'Farscape'
}, {
id: 3,
show: 'Firefly'
}, {
id: 4,
show: 'Star Trek'
}, {
id: 5,
show: 'Star Wars: Christmas Special'
}]
});
var panel = new Ext.panel.Panel({
layout: {
type: 'vbox',
align: 'stretch'
},
items: [{
xtype: 'textfield',
fieldLabel: 'One Two Three Four Five Six Seven',
labelAlign: 'top',
width: '100%'
}, {
xtype: 'tagfield',
fieldLabel: 'One Two Three Four Five Six Seven',
labelAlign: 'top',
store: shows,
displayField: 'show',
valueField: 'id',
queryMode: 'local',
filterPickList: true,
width: '100%',
listeners: {
resize: function () {
debugger, //the event is not fired
}
}
}]
})
var window = new Ext.Window({
layout: 'anchor',
title: 'Hello resizer',
resizable: {
dynamic: true
},
draggable: true,
scrollable: 'vertical',
items: [panel],
width: 400,
height: 200,
});
window.show();
}
});
As it is said in API docu:
This event does not fire on components that use cfg-liquidLayout, such as Ext.button.Button and Ext.form.field.Base.

How to add search filter in EXTJS

I created a table using extjs where it is having three columns name, email and cars. In extjs we are having a default sorting method. here i want to add search method for all these three columns so that i can also search using the name, email and cars.
What change i need to do for the below code
The expected output is i need to get search filter option under each columns.
Ext.define('ViewerModel', {
extend: 'Ext.app.ViewModel',
alias: 'viewmodel.viewermodel',
stores: {
mystore: {
fields: ['name', 'email', 'cars'],
data: {
'items': [{
'name': 'Lisa',
"email": "lisa#simpsons.com"
}, {
'name': 'Bart',
"email": "bart#simpsons.com"
}, {
'name': 'Homer',
"email": "homer#simpsons.com"
}, {
'name': 'Marge',
"email": "marge#simpsons.com"
}]
},
proxy: {
type: 'memory',
reader: {
type: 'json',
rootProperty: 'items'
}
}
}
}
});
Ext.define('APP.HorizontalBox', {
extend: 'Ext.container.Container',
requires: ['Ext.layout.container.HBox'],
xtype: 'layout-horizontal-box',
width: 750,
height: 300,
layout: {
type: 'hbox',
align: 'stretch'
},
bodyPadding: 10,
defaults: {
frame: true,
bodyPadding: 10
},
viewModel: {
type: 'viewermodel'
},
items: [{
xtype: 'grid',
title: 'Grid: click on the grid rows',
itemId: 'myGridItemId',
flex: 1.2,
margin: '0 10 0 0',
bind: {
store: '{mystore}',
selection: '{users}'
},
columns: [{
text: 'Name',
dataIndex: 'name',
flex: 0.5
}, {
text: 'Email',
dataIndex: 'email',
flex: 1
}, {
text: 'Cars',
dataIndex: 'cars',
flex: 1
}],
dockedItems: [{
xtype: 'toolbar',
dock: 'top',
items: [{
xtype: 'button',
padding: '2 5 2 5',
text: 'Edit item',
handler: function (btn) {
var grid = btn.up('grid');
var selectedRow = grid.getSelectionModel().getSelection()[0];
var janela = Ext.create('APP.MyWindow', {
animateTarget: btn.getEl(),
//EDITED
viewModel: {
data: {
users: selectedRow
}
}
}).show();
}
}]
}],
}, {
xtype: 'form',
title: 'View',
itemId: 'panelbindItemId',
flex: 1,
margin: '0 10 0 0',
defaults: {
labelWidth: 50
},
items: [{
xtype: 'displayfield',
margin: '20 0 0 0',
fieldLabel: 'Name',
bind: '{users.name}'
}, {
xtype: 'displayfield',
fieldLabel: 'Email',
bind: '{users.email}'
}]
}]
});
Ext.define('APP.MyWindow', {
extend: 'Ext.window.Window',
alias: 'widget.mywindow',
reference: 'windowreference',
title: 'MyWindow | Edit record',
closable: true,
modal: true,
padding: '10px',
height: 150,
layout: 'fit',
initComponent: function () {
var me = this;
Ext.apply(me, {
items: [{
xtype: 'form',
layout: 'anchor',
defaults: {
padding: '5 0 5 0'
},
items: [{
xtype: 'textfield',
margin: '10 0 0 0',
fieldLabel: 'Name',
bind: '{users.name}'
}, {
xtype: 'textfield',
fieldLabel: 'Email',
bind: '{users.email}'
}]
}]
});
me.callParent(arguments);
}
});
Ext.application({
name: 'Fiddle',
launch: function () {
Ext.create('APP.HorizontalBox', {
renderTo: document.body,
width: 750,
height: 400,
title: 'Title'
});
}
});
You can do it in the afterrender event of grid (Refer this post.) For example:
listeners: {
afterrender: function () {
var menu = Ext.ComponentQuery.query('grid')[0].headerCt.getMenu();
menu.add([{
text: 'Search',
iconCls: 'x-fa fa-home',
handler: function () {
console.log("Search Item");
}
}]);
}
}
Check this Fiddle.
What you are searching for is the FiltersFeature, and the usage is as follows:
xtype:'grid',
...
features:[{
ftype: 'filters',
local: true,
filters: [{
type: 'string',
dataIndex: 'name'
}, {
... (one definition for every column you want to allow filtering one)
}]
}]
Please note that you have to add a requires and maybe even load Ext.ux, as can be found in the last comment.
Other readers please be aware that FiltersFeature is ExtJS4 specific, and has been moved around for ExtJS 5 and 6.
You can also use this code where it will search the data using the date.
listeners: {
afterrender: function () {
var menu = Ext.ComponentQuery.query('grid')[0].headerCt.getMenu();
menu.add([{
xtype:'datefield',
name:'date1',
fieldLabel:'Filter By',
format: 'y-m-d',
listeners:{
renderer: Ext.util.Format.dateRenderer('y-m-d'),
field:{ xtype:'datefield',
autoSync:true,
allowBlank:false,
editor: new Ext.form.DateField(
{format: 'y-m-d'}) }
}
}

Extjs 5 - Link my grid to the Viewmodel

I manage to put the datas I need in a modelView
Controller.js
init: function ()
{
var me = this;
this.mainView = this.getView().add(Ext.create('Tsi.app.tsp_use.details.MainView'));
var customer_id = this.view.customer_id;
var transaction_id = this.view.transaction_id;
this.mainView.on('afterrender', function () {
//Recherche des infos de la transaction
Ext.Ajax.request({
url: '/app/tspuse/detail',
params:
{
customer_id: customer_id,
transaction_id: transaction_id
},
success: function (response)
{
//Passer de l'item "page de chargement" à l'item suivant ici (1)
me.mainView.getLayout().setActiveItem(1);
//response.data tab clef => $valeur
me.mainView.getViewModel().setData(response.data);
console.log('hello : ', response.data);
console.log('hello 2: ', me.mainView.getViewModel());
console.log('hello 3: ', me.mainView.getViewModel().data.vouchers_detail);
}
});
});
},
Here are the datas in the console :
console datas
But I don't know how to bind them to my grind in the third tab of my mainView (see comments) :
Ext.define('Tsi.app.tsp_use.details.MainView', {
extend: 'Tsi.os.view.BaseAppView',
bodyCls: 'DPEW_body_detail',
layout: 'card',
viewModel: {
data: {}
},
items: [{
xtype: 'container',
cls: 'directpayment_detail_help',
layout: 'center',
html: '<p>' + 'directpayment_transaction.wait'._() + '</p>'
}, {
border: false,
xtype: 'tabpanel',
buttonAlign: 'left',
titleAlign: 'left',
plain: true,
tabPosition: 'left',
tabRotation: 0,
defaults: {
border: false,
buttonAlign: 'left',
titleAlign: 'left'
},
listeners: {
tabchange: 'onTabChange'
},
items: [
/**
* FIRST TAB
*/
{
icon: '/img/icons/16/man.png',
bodyStyle: 'background: url(/img/icons/256/Search-Male-User_alpha.png) no-repeat bottom right',
xtype: 'panel',
title: 'directpayment_transaction.tab_user'._(),
tbar: [
'->',
{
xtype: 'container',
text: 'directpayment_transaction.customer.head_text'._()
},
{
icon: '/img/icons/16/text_list_bullets.png',
text: 'directpayment_transaction.customer.show_all_transaction'._(),
handler: 'customerShowAllTransactions'
},
{
icon: '/img/icons/16/Bar-chart.png',
text: 'directpayment_transaction.customer.show_chart_transaction'._(),
handler: 'customerShowStats'
},
],
layout: 'fit',
items: {
border: false,
padding: 10,
xtype: 'fieldcontainer',
labelAlign: 'top',
labelWidth: 100,
defaults: {
margin: 0,
padding: 0,
labelSeparator: '',
hideEmptyLabel: false
},
items: [{
hideLabel: true,
fieldLabel: '',
xtype: 'displayfield',
//pour la date : customer_birth_date:this.toDate -> applique la fonction toDate du Controller
bind: {
value: '{customer_first_name:htmlEncode} {customer_last_name:htmlEncode} - {customer_birth_date:htmlEncode}'
},
cls: 'directpayment_detail_group'
},
{
fieldLabel: 'directpayment_transaction.customer.address'._(),
xtype: 'displayfield',
bind: {
value: '{customer_address:htmlEncode}'
}
},
{
fieldLabel: ' ',
xtype: 'displayfield',
bind: {
value: '{customer_zipcode:htmlEncode} {customer_city:htmlEncode}'
}
},
{
fieldLabel: ' ',
xtype: 'displayfield',
bind: {
value: '{customer_country:htmlEncode}'
}
},
{
fieldLabel: 'directpayment_transaction.customer.phone'._(),
xtype: 'displayfield',
bind: {
value: '{customer_phone:htmlEncode}'
}
},
{
fieldLabel: 'directpayment_transaction.customer.mobile'._(),
xtype: 'displayfield',
bind: {
value: '{customer_mobile:htmlEncode}'
}
},
{
fieldLabel: 'directpayment_transaction.customer.email'._(),
xtype: 'displayfield',
bind: {
value: '{customer_email:this.toMail}'
}
}
]
}
},
/**
* SECOND TAB
*/
{
icon: '/img/icons/16/money_euro.png',
bodyPadding: 10,
title: 'directpayment.panel_detail.tab_transaction'._(),
bodyStyle: 'background: url(/img/icons/256/shopping-basket-full_alpha.png) no-repeat bottom right',
layout: 'fit',
overflowY: 'auto',
items: {
border: false,
padding: 10,
xtype: 'fieldcontainer',
labelAlign: 'top',
labelWidth: 100,
defaults: {
margin: 0,
padding: 0,
labelSeparator: '',
labelWidth: 200,
hideEmptyLabel: false
},
items: [{
hideLabel: true,
fieldLabel: '',
xtype: 'displayfield',
bind: {
value: '{payment_status:this.renderStatus}'
},
cls: 'directpayment_detail_group'
},
{
fieldLabel: 'directpayment_transaction.transaction.date'._(),
xtype: 'displayfield',
//pour la date : transaction_dtime_creation:this.toDate -> applique la fonction toDate du Controller
bind: {
value: '{transaction_dtime:this.toDateStr}'
}
},
{
fieldLabel: 'directpayment_transaction.transaction.tids'._(),
xtype: 'displayfield',
bind: {
value: '{transaction_tid:htmlEncode}'
}
},
{
fieldLabel: 'directpayment_transaction.transaction.amount'._(),
xtype: 'displayfield',
bind: {
value: '{transaction_amount:this.toMoney}'
}
},
{
fieldLabel: 'directpayment_transaction.transaction.currency'._(),
xtype: 'displayfield',
bind: {
value: '{transaction_currency:htmlEncode}'
}
},
{
fieldLabel: 'directpayment_transaction.transaction.detail'._(),
xtype: 'displayfield',
bind: {
value: '{transaction_detail}'
}
},
{
fieldLabel: 'directpayment_v1_transaction.merchant.name'._(),
xtype: 'displayfield',
bind: {
value: '{merchant_label}'
}
},
]
}
},
/**
* THIRD TAB
*/
{
icon: '/img/icons/16/barcode-16.png',
bodyPadding: 10,
title: 'tsp_use.panel_detail.tab_vouchers.title'._(),
bodyStyle: 'background: url(/img/icons/256/shopping-basket-full_alpha.png) no-repeat bottom right',
layout: 'fit',
overflowY: 'auto',
items: {
border: false,
padding: 10,
xtype: 'grid',
labelAlign: 'top',
labelWidth: 100,
defaults: {
margin: 0,
padding: 0,
labelSeparator: '',
labelWidth: 200,
hideEmptyLabel: false
},
columns: [{
text: 'tsp_use.panel_detail.tab_vouchers.voucher_ticket_sn'._(),
dataIndex: 'voucher_ticket_sn',
flex: 1
},
{
text: 'tsp_use.panel_detail.tab_vouchers.voucher_ticket_amount'._(),
dataIndex: 'voucher_ticket_amount',
flex: 1
},
{
text: 'tsp_use.panel_detail.tab_vouchers.voucher_ticket_balance'._(),
dataIndex: 'voucher_ticket_balance',
flex: 1
},
{
text: 'tsp_use.panel_detail.tab_vouchers.merchant_id'._(),
dataIndex: 'merchant_id',
flex: 1
},
{
text: 'tsp_use.panel_detail.tab_vouchers.merchant_name'._(),
dataIndex: 'merchant_name',
flex: 1
},
{
text: 'tsp_use.panel_detail.tab_vouchers.merchant_address'._(),
dataIndex: 'merchant_address',
flex: 1
},
{
text: 'tsp_use.panel_detail.tab_vouchers.merchant_zipcode'._(),
dataIndex: 'merchant_zipcode',
flex: 1
},
{
text: 'tsp_use.panel_detail.tab_vouchers.merchant_city'._(),
dataIndex: 'merchant_city',
flex: 1
},
{
text: 'tsp_use.panel_detail.tab_vouchers.merchant_country'._(),
dataIndex: 'merchant_country',
flex: 1
},
],
store: {
fields: [
'voucher_ticket_sn',
'voucher_ticket_amount',
'voucher_ticket_balance',
'merchant_id',
'merchant_name',
'merchant_address',
'merchant_zipcode',
'merchant_city',
'merchant_country'
],
/*
* How to access datas in viewModel ?
*
* bind:{} instead of proxy:{} ?
*
*/
proxy: {
type: 'ajax',
url: '',
pageSize: 25,
reader: {}
},
autoLoad: false
},
}
},
]
}]
});
It works for the displayfield, but I failed to bind the datas to voucher_detail to my grid.
Try it this way:
viewModel: {
data: {
arrayData: undefined
},
stores: {
storeName: {
data: '{arrayData}'
}
}
}
and then you just need to bind the store to the grid.

"Ext.getCmp(...) is undefined" in different function

I have Extjs code in view, this is it:
createPanelMC: function() {
this.requiredSign = '<span style="color:red;font-weight:bold" data-qtip="Required">*</span>';
var panel = Ext.create('Ext.form.Panel', {
defaultType: 'textfield',
name: 'nodebPanel',
width: '100%',
layout: {
type: 'auto',
align: 'stretch'
},
items: [{
xtype : 'fieldset',
name : 'modlayanan',
title : 'Data Pelanggan',
layout : 'column',
width : '95%',
margin : '10',
items: [{
xtype : 'textfield',
name : 'nomor',
id : 'nomor',
fieldLabel : 'PSTN',
emptyText : 'Nomor...',
margin : '10 0 0 0',
width : 350,
labelWidth : 100,
afterLabelTextTpl: this.requiredSign
}, {
xtype : 'textfield',
fieldLabel : 'Speedy',
name : 'speedy',
id : 'speedy',
margin : '10 0 10 20',
width : 350,
labelWidth : 100
},
this.createTreePaketExist()
]
}],
dockedItems: [ {
xtype: 'toolbar',
name: 'tbpaketmc',
dock: 'bottom',
items: [ {
text: '<< Back',
action: 'doBack'
},'->', {
text: 'Submit',
action: 'doSubmit'
}
]
}
]
});
return panel;
},
i call nomor dan speedy in this.createTreePaketExist() . This is the this.createTreePaketExist() code:
createTreePaketExist: function() {
var nopstn= Ext.getCmp('nomor').getValue();
var speedy= Ext.getCmp('speedy').getValue();
var storeTree = Ext.create('Ext.data.TreeStore', {
proxy: {
type: 'ajax',
method: 'POST',
url: 'data/newoss_get_paket.php',
params: {
nopstn:nopstn
,speedy:speedy
}
}
});
var groupProduct = Ext.create('Ext.tree.Panel', {
store : storeTree,
name : 'treeProduct',
rootVisible : false,
useArrows : true,
layout :'fit',
margin : '0 0 0 0',
autoScroll : true,
height : 150,
width : '93%',
listeners:
{
checkchange: function(node, checked, eOpts){
node.eachChild(function(n) {
node.cascadeBy(function(n){
n.set('checked', checked);
});
});
p = node.parentNode;
var pChildCheckedCount = 0;
p.suspendEvents();
p.eachChild(function(c) {
if (c.get('checked')) pChildCheckedCount++;
p.set('checked', !!pChildCheckedCount);
});
p.resumeEvents();
}
}
});
return groupProduct;
},
but it gave an error: Ext.getCmp(...) is undefined. Help me, thanks.
Ext.getCmp() is not recommended to use in ExtJS code. Instead you should use
Ext.ComponentQuery.query('#nomor')
Where nomor is id of element.
But To resolve your problem try to call this:
Ext.ComponentQuery.query('textfield[name="nomor"]')
or
Ext.getCmp('#nomor')
if this will not help you then the problem in your code structure. May be piece of code that represents getCmp('nomor') is loaded and invoked before piece of code that represents your nomor code. This problem may occur if you do not use MVC
The createTreePaketExist will be called during component initialisation, it's unlikely the textfields are actually rendered or even initialised properly at this point, best to use the listeners. You could use refs in your controller to get a reference to these fields automatically or you could listen to the afterrender event and then reference the fields.
I have created a fiddle here that shows how to load the store on form submit, you could also do this on the textfield's change events.
Here is the code for reference:
Ext.application({
name: 'Fiddle',
launch: function() {
var panel = Ext.create('Ext.form.Panel', {
renderTo: Ext.getBody(),
defaultType: 'textfield',
name: 'nodebPanel',
width: '100%',
layout: {
type: 'auto',
align: 'stretch'
},
items: [{
xtype: 'fieldset',
name: 'modlayanan',
title: 'Data Pelanggan',
layout: 'column',
width: '95%',
margin: '10',
items: [{
xtype: 'textfield',
name: 'nomor',
id: 'nomor',
fieldLabel: 'PSTN',
emptyText: 'Nomor...',
margin: '10 0 0 0',
width: 350,
labelWidth: 100,
afterLabelTextTpl: this.requiredSign
}, {
xtype: 'textfield',
fieldLabel: 'Speedy',
name: 'speedy',
id: 'speedy',
margin: '10 0 10 20',
width: 350,
labelWidth: 100
}]
}],
dockedItems: [{
xtype: 'toolbar',
name: 'tbpaketmc',
dock: 'bottom',
items: [{
text: '<< Back',
action: 'doBack'
}, '->', {
text: 'Submit',
action: 'doSubmit',
bindForm: true,
handler: function() {
var nopstn = Ext.getCmp('nomor').getValue();
var speedy = Ext.getCmp('speedy').getValue();
if (nopstn != '' && speedy != '') {
var store = Ext.ComponentQuery.query('#treeProduct')[0].getStore();
console.log(store);
store.load({
params: {
nopstn: nopstn,
speedy: speedy
}
});
}
}
}]
}]
});
var storeTree = Ext.create('Ext.data.TreeStore', {
autoLoad: false,
proxy: {
type: 'ajax',
method: 'POST',
url: 'data/newoss_get_paket.php'
}
});
var groupProduct = Ext.create('Ext.tree.Panel', {
renderTo: Ext.getBody(),
store: storeTree,
itemId: 'treeProduct',
name: 'treeProduct',
rootVisible: false,
useArrows: true,
layout: 'fit',
margin: '0 0 0 0',
autoScroll: true,
height: 150,
width: '93%',
listeners: {
checkchange: function(node, checked, eOpts) {
node.eachChild(function(n) {
node.cascadeBy(function(n) {
n.set('checked', checked);
});
});
p = node.parentNode;
var pChildCheckedCount = 0;
p.suspendEvents();
p.eachChild(function(c) {
if (c.get('checked')) pChildCheckedCount++;
p.set('checked', !! pChildCheckedCount);
});
p.resumeEvents();
}
}
});
}
});

ExtJS 4: even browser not prompt to save entered data into forms fields

ExtJS 4.1.1a
Simple authorization form (login & passowrd).
Even browser not prompt to save entered login and password values unlike standard html form with input's.
Sample code: http://jsfiddle.net/AllanStark/mKMfh/1/
Ext.create('Ext.window.Window', {
title: 'Test',
height: 430,
width: 335,
bodyPadding: '20 0 0 0',
draggable: false,
resizable: false,
closable: false,
layout: {
type: 'vbox',
align: 'center'
},
bodyStyle: {
background: '#FFFFFF'
},
items: [{
xtype: 'image',
width: 150,
height: 150,
src: 'images/logo.gif'
},{
xtype: 'form',
url: 'login.php',
standardSubmit: true,
border: 0,
width: 170,
padding: '20 0 20 0',
defaultType: 'textfield',
layout: 'vbox',
fieldDefaults: {
labelAlign: 'top',
msgTarget: 'qtip',
width: '100%'
},
items: [{
xtype:'textfield',
fieldLabel: 'Login',
name: 'login',
allowBlank: false
},{
xtype:'textfield',
fieldLabel: 'Password',
name: 'pass',
inputType: 'password',
allowBlank: false,
listeners: {
specialkey: function(field, e){
if (e.getKey() == e.ENTER) {
var form = field.up('form').getForm();
form.submit();
}
}
}
}],
buttons: [{
text: 'Ok',
formBind: true,
disabled: true,
handler: function() {
var form = this.up('form').getForm();
form.submit();
}
},{
text: 'Reset',
handler: function() {
this.up('form').getForm().reset();
}
}]
}]
}).show();​
To open the password dialog the html-attribut autocomplete must be "on". In Extjs its "off" and there's no method to change it only a 'workaround'.
So add this event to the listeners of password and username:
afterrender:function(cmp){
cmp.inputEl.set({
autocomplete:'on'
});
}
Ext.create('Ext.window.Window', {
title: 'Test',
height: 430,
width: 335,
bodyPadding: '20 0 0 0',
draggable: false,
resizable: false,
closable: false,
layout: {
type: 'vbox',
align: 'center'
},
bodyStyle: {
background: '#FFFFFF'
},
items: [{
xtype: 'image',
width: 150,
height: 150,
src: 'images/logo.gif'
},{
xtype: 'form',
url: 'login.php',
standardSubmit: true,
border: 0,
width: 170,
padding: '20 0 20 0',
defaultType: 'textfield',
layout: 'vbox',
fieldDefaults: {
labelAlign: 'top',
msgTarget: 'qtip',
width: '100%'
},
items: [{
xtype:'textfield',
fieldLabel: 'Login',
name: 'login',
allowBlank: false,
listeners: {
// ------
afterrender:function(cmp){
cmp.inputEl.set({
autocomplete:'on'
});
}
// ------
}
},{
xtype:'textfield',
fieldLabel: 'Password',
name: 'pass',
inputType: 'password',
allowBlank: false,
listeners: {
specialkey: function(field, e){
if (e.getKey() == e.ENTER) {
var form = field.up('form').getForm();
form.submit();
}
},
// ------
afterrender:function(cmp){
cmp.inputEl.set({
autocomplete:'on'
});
}
// ------
}
}],
buttons: [{
text: 'Ok',
formBind: true,
disabled: true,
handler: function() {
var form = this.up('form').getForm();
form.submit();
}
},{
text: 'Reset',
handler: function() {
this.up('form').getForm().reset();
}
}]
}]
}).show();​

Resources