ExtJS: Removing and Readding a FormPanel into a Window - extjs3

I'm having a problem where I would like to remove a FormPanel from a Window.
Here is my Form which is being loaded in a Window:
myForm = new Ext.FormPanel({
frame: true,
width: '100%',
id: 'myform',
layout: 'form',
autoHeight: true,
autoDestroy: false,
region: 'center',
monitorValid: true,
items: [{
xtype: 'textfield',
id: 'mytextfield',
fieldLabel: 'My Label',
}]
});
MyWindow = new Ext.Window({
title: 'MyWindow',
layout: 'auto',
resizable: false,
width: 717,
autoheight:true,
id:'mywindow',
closeAction:'hide',
closable: true,
items:[Ext.getCmp("myform")]
});
Now I want to remove this form and have to show another form, and I'm doing like this somewhere else:
MyWindow.removeAll();
MyWindow.add(Ext.getCmp("myAnotherForm"));
But this gives me error "Uncaught TypeError: Cannot read property 'events' of undefined" in ext-all-debug.js.
Is there anything, I'm missing here ?
Thanks.

You can remove the form and add another form by using the following code:
Ext.onReady(function() {
var btn = new Ext.Button({
id : 'button',
width : 100,
height : 30,
text : 'click me',
listeners : {
click : function(){
var myanother = myAnotherForm;
var anotherbtn = btn1;
Mywindow.removeAll();
Mywindow.add(myanother);
Mywindow.add(anotherbtn);
Mywindow.doLayout();
}
}
});
var btn1 = new Ext.Button({
id : 'button1',
width : 100,
height : 30,
text : 'Another button'
});
myAnotherForm = new Ext.FormPanel({
frame: true,
width: '100%',
id: 'myanotherform',
layout: 'form',
autoHeight: true,
autoDestroy: false,
region: 'center',
monitorValid: true,
items: [{
xtype: 'textfield',
id: 'mytextfield',
fieldLabel: 'My Another Label',
}]
});
myForm = new Ext.FormPanel({
frame: true,
width: '100%',
id: 'myform',
layout: 'form',
autoHeight: true,
autoDestroy: false,
region: 'center',
monitorValid: true,
items: [{
xtype: 'textfield',
id: 'mytextfield',
fieldLabel: 'My Label',
}]
});
var Mywindow = new Ext.Window({
title: 'MyWindow',
layout: 'auto',
resizable: false,
width: 317,
autoheight:true,
id:'mywindow',
closeAction:'hide',
closable: true,
items : [myForm,btn]
});
Mywindow.show();
});
The working sample for the above is follows:
http://jsfiddle.net/kesamkiran/MVewR/1/
* Click on 'click me' button then you will get the another form with another button.If you want to change only form,then you can remove the button.

Related

comments between form fields in ext.js 2.3

I am new to ext.js and this may seem easy to some of you but not to me.
I have a form that is build with ext.js version 2.3. I am trying to place comments between the form fields. I mean the following:
inputLabel1: text form input
commentLabel: some text
inputLabel2: text form field
I am having difficulty with the second line above. I don't need it to be an input field - just a label and some text next to it, which are aligned with the form labels and input fields on the rest of the rows.
Input fields are defined as follows:
var formParts =
this.formParts = [];
var receiptAmount = new Ext.Form.NumberField( {
id: 'receiptAmount',
name: 'receiptAmount',
cls:'inputNoRightBorder ',
fieldLabel: messages.amount,
allowNegative: true,
hideLabel: false,
decimalSeparator: messages.decimalSeparator,
decimalPrecision: 2,
groupingSeparator: messages.groupingSeparator,
value: 0,
labelSeparator: messages.asteriskLineBreaker
} );
Then they are placed in containers:
var grossAmount = {
border: false,
layout: 'column',
labelWidth: 190,
cls: 'labelStyle',
border: true,
baseCls: 'ourPanel',
items: [
{
id: 'receiptAmountContainer',
border: false,
layout: 'form',
items: [receiptAmount]
},
{
id: 'receiptCurrencyContainer',
border: false,
layout: 'form',
items: [receiptCurrency]
}
]
};
The latter are placed in field sets:
var receiptFinancialData = {
id: "receiptFinancialData",
border: false,
layout: 'column',
labelWidth: 120,
cls: 'column-style',//'#background-color: #DFE8F6',
border: true,
baseCls: 'ourPanel',
height: 50,
title: messages.taxRate + ':',
header: false,
items: [
receiptExchangeRateMirror,
receiptExchangeAmountMirror,
{
border: false,
layout: 'form',
items: [grossAmount]
},
{
border: false,
layout: 'form',
cls: 'labelStyle',
items: [taxRate]
}
]
};
And again:
var singleLineItemContainer = new Ext.form.FieldSet( {
id: 'singleLineItemContainer',
name: 'singleLineItemContainer',
cls: 'singleLineItemContainer',
isActive: true,
hideLabel: true,
height: 'auto',
items: [
referenceCurrency,
receiptType,
entertainmentType,
receiptFinancialData
]
} );
And again:
var lineItemsContainer = new Ext.form.FieldSet( {
id: 'lineItemsContainer',
name: 'lineItemsContainer',
header: false,
border: false,
height: 'auto',
anchor: '100%',
items: [
toggleSingleMultyContainer,
singleLineItemContainer,
multipleLineItemsContainer,
currencyAndExchangeSet
]
} );
And again:
var generalData = new Ext.form.FieldSet( {
id: 'generalReceiptData',
name: 'generalReceiptData',
header: false,
border: false,
height: 'auto',
anchor: '100%',
items: [
receiptClass,
{
id: 'generalDataReceiptCountryAndDate',
border: false,
layout: 'column',
labelWidth: 120,
cls: 'column-style',//'#background-color: #DFE8F6',
border: true,
baseCls: 'ourPanel',
height: 50,
header: false,
items: [
{
id: 'generalDataReceiptDate',
border: false,
layout: 'form',
cls: 'dateField',
items: [receiptDate]
},
{
id: 'generalDataReceiptCountry',
border: false,
layout: 'form',
items: [receiptCountry]
}
]
},
receiptDateString,
receiptDescription,
isCompanyPaid,
lineItemsContainer
]
} );
The code above is placed in
Ext.extend( receiptForm, Ext.form.FormPanel,{
initComponent: function(){
above code
}
}
There's multiple ways to do this I'm sure. Here's a quick way to sorta hack it with css and readOnly fields
fiddle
items: [{
fieldLabel: 'inputLabel1',
}, {
fieldLabel: 'commentLabel',
readOnly:true,
style:'background: transparent;border: none;',
value:'some text',
}, {
fieldLabel: 'inputLabel2',
}],
This page has some nice ext 2.3 examples, but why not learn with a newer version?

Collapse Filter Panel in dockedItems

Hello i`m struggeling with docked items im trying to collapse my filter panel but this doenst work also the colappse arrow is on the wrong side has anybody an idea how i can fix it. Im Creating an getFilterPane and return it in initComponenet as an toolbar item.
Ext.define('Shopware.apps.SDG.view.update.Grid', {
extend: 'Ext.grid.Panel',
region: 'center',
collapsible: false,
split: true,
title: 'Update Log',
getPagingBar: function () {
var me = this;
me.store = Ext.create('Shopware.apps.SdgArticleUpdateImportLog.store.SdgArticleUpdateLog');
return Ext.create('Ext.toolbar.Paging', {
store: me.store,
dock: 'bottom',
displayInfo: true,
region: 'south'
});
},
getFilterPanel: function () {
var me = this;
return Ext.create('Ext.form.Panel', {
store: me.store,
title: 'Filters',
collapsible: true,
cls: 'detail-view',
width: 300,
region: 'east',
dock: 'right',
layout: {
type: 'vbox',
pack: 'start',
align: 'stretch'
},
defaultType: 'textfield',
items: [{
fieldLabel: 'Sku',
name: '1',
allowBlank: true,
listeners: {
change: function (field, value) {
me.store.filter('sku', value);
me.store.filters.clear();
}
}
}, {
fieldLabel: 'Timestamp',
name: '2',
allowBlank: true,
listeners: {
change: function (field, value) {
me.store.filter('importTimestamp', value);
me.store.filters.clear();
}
}
}]
});
},
createFilterPanel: function () {
},
initComponent: function () {
var me = this;
me.dockedItems = [me.getPagingBar(), me.getFilterPanel(),
{
xtype: 'toolbar',
dock: 'top',
items: [
, '->',
{
xtype: 'textfield',
name: 'searchfield',
cls: 'searchfield',
width: 175,
emptyText: '{s name="CoeSeoRoute/Toolbar/Search"}Suche{/s}',
enableKeyEvents: true,
clearable: true,
checkChangeBuffer: 500,
listeners: {
change: function (field, value) {
me.store.filter('search', value);
me.store.filters.clear();
}
}
}
]
}
];
me.columns = me.getColumns();
me.callParent();
},
Try setting collapseDirection..
From the docs:
collapseDirection : String
The direction to collapse the Panel when the toggle button is clicked.
Defaults to the headerPosition
Important: This config is ignored for collapsible Panels which are direct child items of a border layout.
Specify as 'top', 'bottom', 'left' or 'right'.
Available since: 4.0.0

ExtJS Using a Combobox in a popup window

I'm trying to add a combobox to a floating (popup) form panel in ExtJS. But I'm getting a "Cannot set property 'component' of null" error and the window will not load.
I use the following code in a controller to create the window:
onTreeAddDocClick: function () {
var f = new Ext.form.Panel({
frame: false,
header: false,
floating: true,
closable: true,
items: [{
xtype: 'addDoc'
}]
});
f.show();
}
The code for the window itself is as follows:
Ext.define('OPENhrm.view.dossier.widget.popup.AddDoc', {
extend: 'Ext.form.Panel',
xtype: 'addDoc',
requires: [
'Ext.layout.container.VBox'
],
controller: "dossier-addDoc",
viewModel: {
type: "dossier-addDoc"
},
id: 'addDocForm',
frame: true,
title: 'Add document',
width: 400,
bodyPadding: '10 10 0',
layout: 'form',
closable: true,
defaults: {
anchor: '100%',
allowBlank: false,
msgTarget: 'side',
labelWidth: 50
},
items: [{
// item selector
xtype: 'filefield',
emptyText: 'Select Document',
fieldLabel: 'Document',
name: 'filePath',
id: 'filePath',
buttonText: 'upload document',
buttonConfig: {
icon : '/resources/images/icons/add.jpg'
}
}, {
xtype: 'combo',
fieldLabel: 'Test',
hiddenName: 'test',
store: new Ext.data.SimpleStore({
data: [
['Test1'],
['Test2']
],
id: 0,
fields: ['text']
}),
valueField: 'text',
displayField: 'text',
triggerAction: 'all',
editable: false
}],
// buttons
buttons: [{
text: 'Add',
handler: 'onAddDockClick'
}, {
text: 'Reset',
handler: function () {
this.up('form').getForm().reset();
}
}]
});
If I remove the combobox, the window works just fine. If I place the combobox in a form somewhere else in my application (e.g. on a page with 2 panels; a searchfilter/form and a grid with search results), it works just fine. That other page however, is not a floating/popup window.
I got it to work by defining the whole page in the controller, but as I'm using a MVC structure, that doesn't seem like the way to go. Does anyone know how to get the combobox to work in a floating window, without putting the whole code for that window in the controller?

ExtJS5 Download Excel File

I have a form defined that I use to submit to a PHP script that will create an Excel Spreadsheet using PHPExcel.
Ext.define('Admin.view.main.LedgerParams',{
extend: 'Ext.window.Window',
xtype: 'ledgerparams',
title: 'Generate Account Ledger',
defaultFocus: '[name=period]',
layout: 'fit',
closable: false,
resizable: false,
modal : true,
standardSubmit: true,
items: [{
xtype: 'form',
layout: 'fit',
fieldDefaults: {labelWidth: 80,labelAlign: 'right'},
padding: 10,
items: [{
xtype: 'fieldset',
padding: 10,
title: '<b>Account Ledger Parameters</b>',
defaultType: 'numberfield',
defaults: {enforceMaxLength: true},
items:[{
name: 'period',
flex : 1,
fieldLabel: 'Fiscal Period',
selectOnFocus: true,
value: new Date().getFullYear(),
minValue: 1980
}]
}]
}],
buttons:[{
text: 'Generate',
handler: 'onClick_btnLedgerPrint'
},{
text: 'Cancel',
handler: function(){this.up('window').destroy();}
}]
});
The onClick_BtnLedgerPrint method in the main controller calls the form submit:
onClick_btnLedgerPrint: function(btn){
btn.up('window').down('form').submit({
url: 'app/data/Reports.php',
params: {action:'print',reportname:'generate_ledger'}
});
}
however it appears that a JSON response is required by the form from the server instead of initiating the download. Is the standardSubmit broken in ExtJS5? Any help would be appreciated!
JavaScript cannot initiate the download, same as Ext JS. Only browser does this.
var formValues = btn.up('window').down('form').getForm().getValues();
var params = { action: 'print', reportname: 'generate_ledger' };
var requestParams = Ext.merge(formValues, params);
var url = 'app/data/Reports.php?' + Ext.Object.toQueryString(requestParams);
document.location = url;
Or you can try to use method with iframe described here

Passing variables through URL in Jqgrid to controller in mvc

How do I pass values from url to Jqgrid, the issue is the Jqgrid needs to be loaded based on edit link on previous page, and we have the URL like:
http://localhost:49771/Search/EditSearchResults?id=ID_HelpTopics&action=edit
I need to be able to use this id in URL for populating the grid data, so I need to pass this value through grid to controller to get the results and the grid I have is like:
$("#list").jqGrid({
url: '<%= Url.Action("EditSearchResults", new {controller = "JSonData" }) %>',
datatype: 'json',
colNames: ['Language', 'ID'],
colModel: [
{ name: 'Language', index: 'Language', editable: false, width: 40, align: 'left', sortable: false },
{ name: 'ID', index: 'ID', width: 40, editable: true, edittype: "text", align: 'left', editoptions: { size: 5, maxlength: 30 }, sortable: false }, ],
editurl: '<%= Url.Action("EditSearchResults", new {controller = "JSONData"}) %>',
pager: '#pager',
//autowidth: true,
width: "500",
autowidth: true,
rowNum: 20,
height: "200",
loadonce: false,
rowList: [5, 10, 20, 50],
recordtext: "View Records {0} - {1} of {2}",
emptyrecords: "No records to view",
loadtext: "Loading...",
pgtext: "Page {0} of {1}",
sortname: 'Results',
sortorder: "desc",
viewrecords: true,
scroll: false,
loadonce: false,
caption: 'Edit Search Results',
ondblClickRow: function (id) {
if (id != null) {
jQuery('#grid').jqGrid('restoreRow', lastsel);
jQuery('#list').jqGrid('saveRow', id);
jQuery('#list').jqGrid('editRow', id, true, false, processEdit);
lastsel = id;
}
}
});
});
How can use the current URL to pass id to controller to populate jqgrid, How should the controller and jqgrid should be like? Any ideas?
Url.Action will take a anonymous object as a parameter set
url: '<%= Url.Action("EditSearchResults",
new {controller = "JSonData" },
new {id = Request.Params[id] }) %>',
However it would be preferable to make that part of your model than depending on the Request.