I am using ExtJs for my Application. I made a window in which i have some fields . one field is name which is changing each time when window show.
but since i am not destroying window on button click it not rendering again and showing previous data only. How I make sure for new data.
My code
Code of My Field in form reside in window
items: [
{
xtype: 'combobox',
name: 'Assigned To',
queryMode: 'local',
store: this.getResourceStore(),
displayField: 'svmx_name',
labelAlign: 'top',
fieldLabel: 'Assigned_To',
listeners: {
scope: this,
select: function (combo, record, index) {
var form = display_form.getForm();
var id = record.getId();
form.findField('ResourceId').setValue(id);
},
afterrender: function (combo, record, index) {
console.log(this.getResourceName());
combo.setValue(this.getResourceName());
},
}
},
Setting fields in window.
if (!this.win) {
this.win = Ext.widget({
xtype: 'editorwindow',
resourceStore: Ext.getCmp('scheduler1').getResourceStore(),
eventStore: Ext.getCmp('scheduler1').getEventStore(),
wrapper: Ext.getCmp('scheduler1').getWrapper(),
resourceName: targetResource,
startdate: date,
targetData: dragSource.data,
});
}
this.win.show();
I would define an own window class with a config object to set your required data.
The framework will create setter and getter functions for you.
Ext.define(MyFieldsWindow, {
extend: Ext.window.Window,
xtype: 'myfieldswindow',
config: {
resourceName: '',
startdate: null,
targetData: null
},
}
In the update function set the value to the specific component.
The updateResourceName function will look like.
updateResourceName: function (newResourceName, oldResourceName) {
var resourceNameCmp = this.getComponent('resourceName');
resourceNameCmp.setValue(newResourceName);
},
Now you can set the config when you create an instance.
if (!this.win) {
this.win = Ext.create({
xtype: 'myfieldswindow',
resourceStore: Ext.getCmp('scheduler1').getResourceStore(),
eventStore: Ext.getCmp('scheduler1').getEventStore(),
wrapper: Ext.getCmp('scheduler1').getWrapper(),
resourceName: targetResource,
startdate: date,
targetData: dragSource.data,
});
}
this.win.show();
Or you can set it at runtime with the setter method.
this.win.setResourceName('Roli Agrawal');
The window class looks like.
Ext.define(MyFieldsWindow, {
extend: Ext.window.Window,
config: {
resourceName: '',
startdate: null,
targetData: null
},
updateResourceName: function (newResourceName, oldResourceName) {
var resourceNameCmp = this.getComponent('resourceName');
resourceNameCmp.setValue(newResourceName);
},
updateStartDate: function () {/*similar code like above*/ },
updateTargetDate: function () {/*similar code like above*/ },
items: [
{
itemId: 'resourceName',
xtype: 'textfield'
},
/* additional items*/
]
});
Related
I am still learning EXTJs and one of the thing I was trying to to was extend a component. Below is my example:
Ext.define('MyApp.view.CustomTextField',{
extend: 'Ext.field.Text',
xtype: 'customtextfield',
config:
{
fieldID: null,
langID: null
},
initialize: function() {
alert("init"); //1. called before I navigate to view
Call a controller method here
this.callParent(arguments);
},
initComponent: function () {
alert("initComp"); //2. not called at all
Call a controller method here
this.callParent(arguments);
}
I want to call a controller method to validate if user has permission to see this field and accordingly do next actions. I want this validation to happen when I navigate to the view
I used this custom field in my View as:
xtype: 'fieldset',
margin: 10,
bind: '{workOrders}',
title: 'Dispatch Information',
items: [
{
id: 'Tag',
xtype: 'customtextfield',
name: 'Tag',
label: 'Tag',
bind: '{Tag}',
labelAlign: 'top'
},
But the initComponent is never fired.
The initialize is fired to soon ,even before my stores are loaded. How do I properly extend this control?
In ExtJS 6 modern there is no initComponent event for textfield . initComponent event have
in classic for textfield.
For calling events in controller you need to create controller and define to you view.
In this FIDDLE, I have created a demo using form, ViewController, textfield and ViewModel. I hope this will help/guide you to achieve your requirements.
For more details please refer ExtJS Docs.
CODE SNIPPET
Ext.application({
name: 'Fiddle',
launch: function () {
//Define the cutsometext from extending {Ext.field.Text}
Ext.define('CustomText', {
extend: 'Ext.field.Text',
xtype: 'customtext',
labelAlign: 'top',
listeners: {
initialize: 'onInitializeCutsomText'
}
});
Ext.define('FormModel', {
extend: 'Ext.app.ViewModel',
alias: 'viewmodel.formmodel',
data: {
user: {
firstName: 'Narendra',
lastName: 'Jadhav',
email: 'narendrajadhav105#gmail.com'
},
permissionCng: {
firstName: false,
lastName: false,
email: true,
isAdmin: false
}
}
});
//Define the FormController from extending {Ext.app.ViewController}
Ext.define('FormController', {
extend: 'Ext.app.ViewController',
alias: 'controller.formctn',
onInitializeCutsomText: function (textfield) {
var permissionCng = this.getViewModel().get('permissionCng');
// Here is just basic example for disabled textfield on initialize event.
//In your case you can put your requirement.
textfield.setDisabled(permissionCng[textfield.getName()]);
}
});
//Creating form
Ext.create('Ext.form.Panel', {
fullscreen: true,
viewModel: {
type: 'formmodel'
},
controller: 'formctn',
items: [{
xtype: 'fieldset',
title: 'Personal Info',
defaults: {
xtype: 'customtext' //Here I am using {customtext}
},
items: [{
label: 'First Name',
name: 'firstName',
bind: {
value: '{user.firstName}',
//You can also use like property
//hidden:'{permissionCng.firstName}'
}
}, {
label: 'Last Name',
name: 'lastName',
bind: {
value: '{user.lastName}',
//You can also use like property
//hidden:'{permissionCng.firstName}'
}
}, {
label: 'Email Id',
name: 'email',
bind: {
value: '{user.email}',
//You can also use like property
//hidden:'{permissionCng.firstName}'
}
}, {
label: 'Admin Name',
name: 'isAdmin',
bind: {
value: '{user.isAdmin}',
//You can also use like property
hidden: '{!permissionCng.isAdmin}'
}
}]
}]
});
}
});
I've built a master/detail form in ExtJS4 as an exercise of learning ExtJS.
I want to pass down id from master table to the detail form when i'm creating a new article.
When the create button is pressed in detailGrid, the id is passed to the controller. In the controller I can see the output of the id via console.log so I know it is present in the controller.
How can I pass it to the form?
Controller:
{
var detailgrid = button.up('userdetail');
var parentId = detailgrid.getParentId();
console.log(parentId);
var view = Ext.widget('detailadd');
},
The Form where I need to get parentId from the controller
Ext.define('calsberg.view.user.DetailsAdd', {
extend: 'Ext.window.Window',
alias: 'widget.detailadd',
title: 'Add Artikli',
config:
{
parentId: parentId
},
layout: 'fit',
autoShow: true,
initComponent: function () {
this.items = [
{
xtype: 'form',
bodyStyle: {
background: 'none',
padding: '10px',
border: '0'
},
items: [
{
xtype: 'textfield',
name: 'parentId',
value: this.getParentId()
},
{
xtype: 'textfield',
name: 'sifra',
allowBlank: false,
fieldLabel: 'Šifra'
},
{
xtype: 'textfield',
name: 'naziv',
allowBlank: false,
vtype: 'naziv',
fieldLabel: 'Naziv'
},
You can either put the variable in the global namespace so that you can reference it from anywhere in the App e.g.
// MyApp would already be initialised in app.js
MyApp.parentId = detailgrid.getParentId();
// then you could reference it anywhere else thereafter
Ext.define('calsberg.view.user.DetailsAdd', {
extend: 'Ext.window.Window',
alias: 'widget.detailadd',
title: 'Add Artikli',
config:
{
parentId: MyApp.parentId
}
.....
Or you could pass in a config object when you create the widget such as this
var detailgrid = button.up('userdetail');
var parentId = detailgrid.getParentId();
console.log(parentId);
var view = Ext.widget('detailadd', {config:{parentId:parentId}});
I have some code that is pulling a Release model back and displaying in a grid, this is working fine, but I cannot work out how to inspect what is in the returned model.
What I would like is to get the contents of the model in some kind of object that I can reorganise or drill into as I see fit (in this case the release model).
If I add a component and just dump the model into the html it is not returning the contents as I would expect.
Rally.data.ModelFactory.getModel({
type: 'Release',
success: function(model) {
this.add({
xtype: 'component',
html: model
});
this.grid = this.add({
xtype: 'rallygrid',
model: model,
columnCfgs: [
'FormattedID',
'Name',
'RevisionHistory' ],
storeConfig: {
filters: queryFilters
}
});
},
scope: this
});
If I dig into the ExtJS docs it seems I should be able to do something like getData() on the model to return the contents but this is not working.
Inspection in the debugger tells me I have a "Rally.domain.v2.0.project.10098485624.Release" object but I can't see how to simply access the list of items in the object. Obviously there is a way because passing this model to a grid component will display it quite happily.
The debugger for this object shows me a number of further functions to call but I have no idea which one or how to use it
...
getArtifactMappings: function () {
getCollectionFields: function () {
getCustomFields: function () {
getField: function (fieldName) {
getFields: function () {
getFieldsByName: function (fieldNames) {
getName: function () {
getNonCollectionFields: function () {
getPermissionLevels: function (permission) {
getProxy: function () {
etc...
The Rally docs indicate I should be able to call getData() on a model https://help.rallydev.com/apps/2.0rc2/doc/#!/api/Rally.data.Model but it looks like the ModelFactory.getModel() is not returning a type that has a getData() method
A model is a class, and a record is an instance of that class.
getData() will work on a record.
There are static methods that would work on the actual model, but getData() is not one of them.
Here is a fragment from the code below:
_onDataLoaded: function(store, data){
_.each(data, function(record){
var r = record.getData();
console.log('release', r);
This code builds a grid of Releases filtered by project and ReleaseStartDate. I noticed that in your code you want to display model information, maybe for debug purposes, by actually modifying the dom. I would prefer to use console.log, but in the example below I did both. I used a border layout with a footer, and set html proprety of the container in the footer to JSON.stringify(r)
Ext.define('CustomApp', {
extend: 'Rally.app.App',
componentCls: 'app',
layout:'border',
defaults: {
collapsible: true,
split: true,
bodyStyle: 'padding:15px',
},
items: [{
title: 'data',
region:'south',
itemId: 'd',
margins: '5 0 0 0',
cmargins: '5 5 0 0'
},{
title: 'Releases',
itemId: 'r',
collapsible: false,
region:'center',
margins: '5 0 0 0'
}] ,
launch: function() {
var context = this.getContext();
var projectId = context.getProject().ObjectID;
var millisecondsInDay = 86400000;
var currentDate = new Date();
var startDate = new Date(currentDate - millisecondsInDay*90); //in the last 90 days
var startDateUTC = startDate.toISOString();
Ext.create('Rally.data.WsapiDataStore', {
model: 'Release',
fetch: ['Name','ReleaseStartDate','ReleaseDate', 'State'],
filters: [
{
property: 'ReleaseStartDate',
operator: '>',
value: startDateUTC
},
{
property: 'Project',
operator: '=',
value: '/project/'+ projectId
}
],
autoLoad: true,
listeners: {
load: this._onDataLoaded,
scope: this
}
});
},
_onDataLoaded: function(store, data){
var text = '';
_.each(data, function(record){
var r = record.getData();
console.log('release', r);
text = text + JSON.stringify(r);
});
console.log('text', text);
this.down('#d').add({
xtype:'container',
html: text
});
if (!this.down('#g')) {
this.down('#r').add({
xtype: 'rallygrid',
store: store,
itemId: 'g',
columnCfgs: [
{
text: 'Name', dataIndex: 'Name'
},
{
text: 'State', dataIndex: 'State'
},
{
text: 'Start Date', dataIndex: 'ReleaseStartDate', flex:1
},
{
text: 'Release Date', dataIndex: 'ReleaseDate',flex:1
}
]
});
}
else{
(this.down('#g')).reconfigure(store);
}
}
});
I am unable to set the value for the textfield which is inside fieldcontainer. I want to set the value and other config for the "textfield" which is inside the "fieldcontainer". So basically i set the configuration for the textfield which i receive from the server, like for example : allowBank: true , maxlength: 4, value: 'Hello World' i get from the server and want to supply it to the textdfield which is inside my custom control which is fieldcontainer. All other configuration is applied except for the value config using the built in textConfig. Below is my code:
Ext.define('PTextField', { extend: 'Ext.form.FieldContainer',
alias: 'widget.ptextfield',
requires: ['Ext.form.TextField', 'Ext.Img'],
width: 170,
fieldLabel: 'Empty Label',
labelAlign: 'top',
layout: {
type: 'hbox'
},
BLANK_IMAGE_URL: '',
constructor: function (config) {
this.callParent(arguments);
Ext.apply(this.down('textfield'), this.textConfig);
Ext.apply(this.down('image'), this.imgConfig);
}, // eo function constructor
initComponent: function () {
var me = this;
this.textBox = this.createTextField();
this.imageBox = this.createImagefield();
this.items = [this.imageBox, this.textBox];
this.callParent(arguments);
}, //eo initComponent
createTextField: function () { return {xtype: 'textfield'} },
createImagefield: function () { return { xtype: 'image', height: 20, width: 20} }
});
var fname = Ext.create('PTextField', {
fieldLabel: 'First Name',
textConfig: { value: 'Hello World', allowBlank: false, readOnly: true, maxLength: 4, width: 100 },
imgConfig: { src: 'http://www.sencha.com/img/20110215-feat-html5.png' }
});
fname.render(Ext.getBody());
I am using extjs 4.1.
Any help is appreciated.
You should simply create the textfield and image using your configs. Then define your items array using the created objects, like this:
initComponent: function() {
var me = this,
textfield = Ext.widget('textfield', me.textConfig),
image = Ext.widget('image', me.imgConfig);
me.items = [textfield, image];
me.callParent(arguments);
},
I would simplify your code to something like that:
Remove whole constructor() function. you don't need it.
Rewrite initComponent() function for your fieldset as:
initComponent: function() {
var me = this;
Ext.apply(me, items: [{
xtype: 'textfield',
value: me.textConfig.value,
....
}, {
xtype: 'image',
src: me.imageConfig.src,
...
}]);
}
I am using extjs 4.1 and trying to do the event delegation which in my case is to attach a blur event to all the textfields of my form and it is not working and i am not getting any error in firebug too, i don't know where i am going wrong in attaching the event, is it the wrong place where i am putting the code and also i have noticed that as per the docs below link:
http://docs.sencha.com/ext-js/4-1/#!/api/Ext.form.Panel-method-on
the delegate property of the options object no longer exists. Below is my code:
Ext.onReady(function () {
var loadForm = function () {
Ext.getCmp('TestForm').getForm().setValues({ name: 'some text', email: 'first', dob: '12/12/2009' });
}
Ext.define('userForm', {
extend: 'Ext.form.Panel'
, alias: 'widget.userform'
, frame: true
, initComponent: function () {
Ext.apply(this, {
title: 'User Form'
, height: 350
, items: [{
xtype: 'textfield'
, fieldLabel: 'Name'
, name: 'name'
, id: 'nameId'
, enableKeyEvents: true
}, {
xtype: 'textfield'
, fieldLabel: 'Email'
, name: 'email'
, id: 'emailId'
}, {
xtype: 'datefield',
fieldLabel: 'DOB',
id: 'dob',
name: 'dob',
format: 'Y-m-d'
}, {
xtype: 'textfield',
fieldLabel: 'Age',
id: 'age',
name: 'age'
}, {
xtype: 'textfield',
fieldLabel: 'Guardian',
id: 'guardian',
name: 'guardian'
}]
});
this.callParent(arguments);
} //eoinitComponent
});
var userForm = Ext.create('userForm', {
renderTo: 'loadPanel',
id: 'TestForm',
listeners: {
afterrender: function (formCmp, eOpts) {
loadForm();
},
render: function (formCmp, eOpts) {
Ext.getCmp("TestForm").on(
'blur',
function (e, t) {
// handle blur
console.info(t.id);
},
this,
{
// filter the target element to be a descendant with the class '.x-form-field'
delegate: '.x-form-field'
}
);
}
}
});
});
To begin with, the on method does not take delegate as a parameter, so that line is completely unnecessary.
Then, within your render event, you can just use formCmp.on() rather than Ext.getCmp().on().
Lastly, you want blur event on every field, not on the form itself. The following code should work:
render: function (formCmp, eOpts) {
// For each field.
formCmp.getForm().getFields().each( function( aField ) {
// If it's a textfield.
if ( aField.is('textfield') ) {
aField.on( 'blur', this.onFieldBlur, this)
}
}, this ); // notice the this scope for the each method.
}