I am not able to get combobox value in a controller. The getter method of combobox view returns
function i(){
return this.constructor.apply(this,arguments)||null
}
instead of view object instance. If I use
var combo=this.getColumnTypeComboView().create()
then I don't get selected value of the combobox combo.getValue().
To get view reference in a controller simply use getView() method from the Controller class. To create a connection between view and a controller make sure that you follow MVC aplication architecture principals, found here
var view = this.getView('Contact'); //=> getView( name ) : Ext.Base
if a combobox is a item of a view that your controller is in charge off, then use control method also from Controller class.
Ext.define('My.controller.Contact', {
extend: 'Ext.app.Controller',
views: ['Contact'],
init: function() {
//reference the view
var view = this.getView('Contact');
//reference the combobox change event
this.control({
'mywin combobox': {
change: this.onChangeContinent
}
});
},
onChangeContinent:function (field, value, options) {
//here you can get combobox component and its value
Ext.Msg.alert('Continent', value);
}
});
here is a fiddle example
EDIT:
To reference one component from another, you can use Controller ref method, like this:
refs: [{
ref: 'combo',
selector: 'mywin combobox'
}]
here is a fiddle example 2
Related
I am new to Extjs,I create a grid panel in extjs, with toolbar. I give a add button, in controller the button name is given. in view, i create a tool bar in create function, not in define. Using alias i create one name also, by using that widget name i used to call in controller, by using button action value give thew function foropen a new, but it notworking. If i use panel within init function in view part means it will not disply any panels.
and my coding is
Ext.create('Ext.toolbar.Toolbar', {
alias : 'widget.toolbar',
renderTo: document.body,
items: [
{
itemId : 'addtab',
text: 'Add',
iconCls: 'add',
action: 'addtab'
}]
})
this is the view part. action here i given as addtab
and my controller is
init: function() {this.control({
'toolbar button[itemId=grid-add]': {
click: function(){
top.addTab(true,"../medias/add","Media","common",0,'add');
}
}
})
button is working.. and my add page is also working fine. but the calling function that is cal by alias is not working. can anyone give the solution.
i want to give the function in controller file only.
thank you..
I am extending extjs Container component and making a custom component but when i am adding an item using add function it's giving an error that the add function doesn't exist for my custom component. How can this happen since add function is available for Container and my component is extending that. Here's the code
var row = Ext.define('TableRow',{
extend: 'Ext.container.Container',
layout: {
type: 'table',
columns: 10
}
});
row.add(); // This line is giving error saying add function is not available for row
Ext.define() is for defining a class. Once the class has been defined, it can be instantiated by calling Ext.create('TableRow');
Ext.define('TableRow',{
extend: 'Ext.container.Container',
layout: {
type: 'table',
columns: 10
}
});
var row = Ext.create('TableRow');
row.add();
I'm using Sencha Touch 2.3. I'm trying to get a Store instance inside a controller in a similar way thats defined in this article http://www.sencha.com/learn/architecting-your-app-in-ext-js-4-part-3/.
I've defined the 'Location' store in the Controller config. I then try to get the store using 2 methods that both fail. First through Ext.getStore and the second through getLocationStore which should be an autogenerated function. Both fail. The first call returns undefined and the second call throws an exception because the function is not available.
Ext.define('MyApp.controller.Location', {
extend: 'Ext.app.Controller',
config: {
refs: {
locationSearchField: '#locationSearchField'
},
control: {
locationSearchField: {
action: 'onSearchAction'
}
},
stores: [ 'Location' ]
},
onSearchAction: function() {
var locationSearchStore = Ext.getStore('Location');
if (locationSearchStore == undefined) {
Ext.Logger.warn('Could not locate locationSearchStore');
locationSearchStore = this.getLocationStore();
if (locationSearchStore == undefined)
Ext.Logger.warn('Could not location locationSearchStore again!');
else
Ext.Logger.info('Success!');
}
else
Ext.Logger.info('Success!');
}
});
You can get your store by: Ext.data.StoreManager.lookup('Location') (if it's called MyApp.store.Location).
To be sure, that you are in the right context in the onSearchAction, try to call console.dir(this); and check that this is the controller object itself
First of all, you want to access store in sencha touch but you have given link of extjs. Second, you need to define your store first and then add it in app.js file. And then you can access your store by Ext.getStore('Location') method. For reference you shold learn this http://miamicoder.com/2012/sencha-touch-2-stores-adding-removing-and-finding-records/
I'm trying to achieve something fairly simple: use a controller to attach an event to a specific control, but am struggling to represent this using Sencha Architect.
I have a button named "Login-Button-Login".
In my controller, if I have the code:
config: {
control: {
"button": {
tap: 'onButtonTap'
}
}
},
onButtonTap: function(button, e, eOpts) {
Ext.Msg.alert("onButtonTap fired");
},
The the button works as expected. This is fine, but obviously it will apply to all buttons. I add a reference to "Login-Button-Login" (not my choice of name!):
config: {
refs: {
loginButtonTap: 'Login-Button-Login'
},
control: {
"button": {
tap: 'onButtonTap'
},
"Login-Button-Login": {
tap: 'onButtonTap2'
}
}
},
But how can I now use the reference "loginButtonTap" as an item in the control object? Whatever I try using the Sencha Architect controls I just end up with "Login-Button-Login" being referenced directly.
Relatedly, how can I link this controller to the "Login" view which contains the button? Surely I don't need to use full selectors for each reference? Clearly even if I could make this work, it currently would not function as Login-Button-Login needs to reference the "Login" view.
Just use an id (or itemId) of the control as the value of the controlQuery in event handler config:
config: {
control: {
"#btnWhatever": {
tap: 'onWhateverTap'
},
}
I prefer to use this method of attaching events to elements, since I am too lazy to do double work - specify the reference to the button, and then specify that reference in event handlers controlQuery. onWhateverTap gets the reference to the button as an argument and most of the time you do not need that reference anywhere else.
can somebody help me with how to extend extjs components using extjs version 4. I am looking for a proper syntax for the same. please help..!!
Following is an example code of extending textfield in ExtJS 4.
Other then using the existing configs and methods, this extended component also has a new config property created and a new method created & associated with an event.
The purpose of component is simple that it displays the label in red color if the value is mandatory, modifies the background color of the field if its readOnly and also changes the background color of the field when focussed.
The code is properly commented. Hope it helps.
Ext.define('Ext.pnc.Textfield', {
extend: 'Ext.form.field.Text',//Extending the TextField
alias: 'widget.pnctextfield',//Defining the xtype
config:{
focusCls:'focusClassFieldPnC',//Providing value for existing config property.
testConfig:'testConfigValue'//Creating a new config. Accessor functions will be created for this one by ExtJS engine
},
constructor:function(cnfg){
this.callParent(arguments);//Calling the parent class constructor
this.initConfig(cnfg);//Initializing the component
this.on('beforerender',this.beforeRender);//Associating a new defined method with an event
},
//Defining a method below and associating this with an event in the constructor above
beforeRender:function(){
if(!this.allowBlank){
this.labelStyle = 'color:#FF0000';
}
if(this.readOnly){
this.fieldCls = 'readOnlyClass';
}
},
//Over-riding a function which already exists in parent class. Note that this has not been associated with any event in constructor as it already defined in parent class
afterRender:function(){
console.log('after render function');
this.callParent();//Calling the parent class method. This can be omitted if not required and is not a must
}
});
.readOnlyClass{
background:#FF0000 !important
}
.focusClassFieldPnC{
background:#00ff00 !important
}
Ext.define('myApp.Grid', {
extend: 'Ext.Grid',
alias: 'widget.mygrid'
....
....
}
now you can use xtype:'mygrid'
Ext.define('BS.view.MyGrid' , {
extend: 'Ext.grid.Panel',
alias: 'widget.my-grid',
// Non-complex config types (booleans, integers, strings) go here
width: 1000,
autoHeight: true
initComponent: function() {
Ext.apply(this, {
// complex configs (objects / arrays) go here
columns: colModel,
});
this.callParent(arguments);
}
});
why not see the src of extjs4's components such as Grid,Table ...
and here are docs:
http://docs.sencha.com/ext-js/4-0/#/guide/components <== important
http://docs.sencha.com/ext-js/4-0/#/guide/class_system
Ext.define('My.custom.Component', {
extend: 'Ext.Component'
});