Trying to get a checkbox to listen for a toggle event from a button - extjs4

I'm new to ExtJS and only have minimal javascript skills in general. I'm going through some assignment to learn ExtJS4 but this one is eluding me. I'm trying to get a listeners to check a checkbox (well all of them but just one at the moment) when a toggle button is toggled. No matter how I write the code, I get a similar error from Firebug:
missing : after property id
togglebtn.toggle: function(tog, true){
Any thoughts on what I'm doing wrong and how to correct it?
Thanks...
var togglebtn = Ext.create('Ext.button.Button', {
enableToggle: true
, text: 'Checked'
});
var mychkbxgrp = Ext.create('Ext.form.CheckboxGroup', {
columns: 3
, alias: 'mycheckboxgroup'
, items:[{
boxLabel: 'Item1'
, name: 'rb'
, inputValue: '1'
, listeners:{
togglebtn.toggle: function(tog, true){
setValue: true
}
}
},{
boxLabel: 'Item2', name: 'rb', inputValue: '2'
},{
boxLabel: 'Item3', name: 'rb', inputValue: '3'
}]
});
Ext.create('Ext.toolbar.Toolbar', {
renderTo: document.body
, width: 600
, height: 40
, items:[{
xtype: 'form'
, height: 30
, width: 180
, bodyPadding: 4
, items:[
mychkbxgrp
]
}
, togglebtn
]
});

AFAIK handlers for events must be functions, and must be defined for this object. You are trying to set toggle handler inside checkbox definition, while it should be on button.
Below is example implementation of that listener
var togglebtn = Ext.create('Ext.button.Button', {
enableToggle: true,
text: 'Checked',
listeners: {
toggle: function(sender, checked){
var container = sender.findParentByType(); // find parent container
var items = container.query('checkboxfield'); // find checkboxes
Ext.each(items, function(i){ // iterate through checkboxes
i.setValue(checked); // check/uncheck
});
}
}
});
And you must remove togglebtn.toggle: function(tog, true){
setValue: true
} from checkbox definition.
Working sample: http://jsfiddle.net/DyctX/

Related

Using a custom Drop Down List field to set a value in a grid

I'm trying to use the Rally 2.1 SDK to set a custom data field (c_wsjf) in a grid. I have a custom drop down list that I want to check the value of (c_TimeCrticalitySizing).
I created c_TimeCrticalitySizing as a feature card field in my Rally workspace with different string values (such as "No decay"). Every drop down list value will set the custom field to a different integer. When I try to run the app in Rally I get this error:
"Uncaught TypeError: Cannot read property 'isModel' of undefined(…)"
I'm thinking the drop down list value may not be a string.
How would I check what the type of the drop down list value is?
How could I rewrite this code to correctly check the value of the drop down list so I can set my custom field to different integers?
Here's my code block for the complete app. I'm still trying to hook up a search bar so for now I directly call _onDataLoaded() from the launch() function.
// START OF APP CODE
Ext.define('CustomApp', {
extend: 'Rally.app.App',
componentCls: 'app',
featureStore: undefined,
featureGrid: undefined,
items: [ // pre-define the general layout of the app; the skeleton (ie. header, content, footer)
{
xtype: 'container', // this container lets us control the layout of the pulldowns; they'll be added below
itemId: 'widget-container',
layout: {
type: 'hbox', // 'horizontal' layout
align: 'stretch'
}
}
],
// Entry point of the app
launch: function() {
var me = this;
me._onDataLoaded();
},
_loadSearchBar: function() {
console.log('in loadsearchbar');
var me = this;
var searchComboBox = Ext.create('Rally.ui.combobox.SearchComboBox', {
itemId: 'search-combobox',
storeConfig: {
model: 'PortfolioItem/Feature'
},
listeners: {
ready: me._onDataLoaded,
select: me._onDataLoaded,
scope: me
}
});
// using 'me' here would add the combo box to the app, not the widget container
this.down('#widget-container').add(searchComboBox); // add the search field to the widget container <this>
},
// If adding more filters to the grid later, add them here
_getFilters: function(searchValue){
var searchFilter = Ext.create('Rally.data.wsapi.Filter', {
property: 'Search',
operation: '=',
value: searchValue
});
return searchFilter;
},
// Sets values once data from store is retrieved
_onDataLoaded: function() {
console.log('in ondataloaded');
var me = this;
// look up what the user input was from the search box
console.log("combobox: ", this.down('#search-combobox'));
//var typedSearch = this.down('#search-combobox').getRecord().get('_ref');
// search filter to apply
//var myFilters = this._getFilters(typedSearch);
// if the store exists, load new data
if (me.featureStore) {
//me.featureStore.setFilter(myFilters);
me.featureStore.load();
}
// if not, create it
else {
me.featureStore = Ext.create('Rally.data.wsapi.Store', {
model: 'PortfolioItem/Feature',
autoLoad: true,
listeners: {
load: me._createGrid,
scope: me
},
fetch: ['FormattedID', 'Name', 'TimeCriticality',
'RROEValue', 'UserBusinessValue', 'JobSize', 'c_TimeCriticalitySizing']
});
}
},
// create a grid with a custom store
_createGrid: function(store, data){
var me = this;
var records = _.map(data, function(record) {
//Calculations, etc.
console.log(record.get('c_TimeCriticalitySizing'));
var timecritsize = record.get('c_TimeCriticalitySizing');
//console.log(typeof timecritsize);
var mystr = "No decay";
var jobsize = record.get('JobSize');
var rroe = record.get('RROEValue');
var userval = record.get('UserBusinessValue');
var timecrit = record.get('TimeCriticality');
// Check that demoniator is not 0
if ( record.get('JobSize') > 0){
if (timecritsize === mystr){
var priorityScore = (timecrit + userval + rroe) / jobsize;
return Ext.apply({
c_wsjf: Math.round(priorityScore * 10) / 10
}, record.getData());
}
}
else{
return Ext.apply({
c_wsjf: 0
}, record.getData());
}
});
// Add the grid
me.add({
xtype: 'rallygrid',
showPagingToolbar: true,
showRowActionsColumn: true,
enableEditing: true,
store: Ext.create('Rally.data.custom.Store', {
data: records
}),
// Configure each column
columnCfgs: [
{
xtype: 'templatecolumn',
text: 'ID',
dataIndex: 'FormattedID',
width: 100,
tpl: Ext.create('Rally.ui.renderer.template.FormattedIDTemplate')
},
{
text: 'WSJF Score',
dataIndex: 'c_wsjf',
width: 150
},
{
text: 'Name',
dataIndex: 'Name',
flex: 1,
width: 100
}
]
});
}
});
// END OF APP CODE
The app works great until I add the if (timecritsize === mystr) conditional.
I also use console.log() to check that I've set all values for timecritsize to "No decay"

Unable to change the value of variable in button click - Sencha

I am trying to change value of variable and i did as instruction in this post but value does not changes.
My codes are as follow:
Ext.define('MyApp.view.OnlineOffline', {
extend: 'Ext.Panel',
alias: "widget.onlineoffline",
config: {
onlineStatus: 0,
items: [
{
xtype: 'container',
layout: 'hbox',
cls: 'offline-wrap',
items:[
{
xtype: 'image',
cls: 'offlineCheck',
id:'onlineButton',
width: 85,
height:20,
listeners: {
tap: function (button)
{
var me = button.up('onlineoffline')
if (!Ext.device.Connection.isOnline())
{
Ext.Msg.alert('Please connect to <br/>working internet Connection?');
this.element.removeCls('onlineCheck');
this.element.addCls('offlineCheck');
me.setonlineStatus(1);
}
else {
if(me.getOnlineStatus())
{
console.log( 'connection yes if' + me.getOnlineStatus());
me.setOnlineStatus(1);
this.element.removeCls('onlineCheck');
this.element.addCls('offlineCheck');
}
else{
this.element.removeCls('offlineCheck');
this.element.addCls('onlineCheck');
me.setOnlineStatus(0);
console.log( 'connection yes else' + me.getOnlineStatus());
}
}
}
}
},
]
}]
}
});
A couple things here...
First, you are initializing me as a global variable, which is a bad idea. Rather than doing this, get a reference to what you have as me using the button:
listeners: {
tap: function (button) {
var me = button.up('onlineoffline')
...
The problem you are having is caused because you're calling the wrong function. Your config parameter is defined as onlineStatus, but you are calling setonlinestatus(). Call me.setOnlineStatus() instead. The camel-casing for the generated getters and setters will be done exactly as your config param, except the first letter will be capitalized.

Searchfield in Sencha touch

I am trying to add a search field to my form in sencha touch 1.1, but after going through examples provided by sencha touch, i could not find out a way to provide a dynamic store to the search field.
I have a store which will fetch data dynamically.
The store contains list of places and when the user enters the first letter of the place,he should be given a list of places starting from that alphabet
Here is the code i have used.
var searchField = new Ext.form.Search({
name : 'search',
placeHolder: 'Search',
useClearIcon: true,
data:siteStore,
autoComplete:true,
});
inputDataForm = Ext.extend(Ext.Panel, {
scroll: 'vertical',
autoDestroy: true,
layout: 'fit',
id:'inputForm',
initComponent: function() {
this.items = [{
xtype: 'form',
cls: 'formClass',
id:'inputImageForm',
bodyPadding: '0',
scroll: 'vertical',
items: [searchField],
}];
inputDataForm.superclass.initComponent.call(this);
}, // End fo initComponent
});
Can somebody please help.
Thank you
This is my code. It is working fine and I have docked the searchfield in a panel.
You can use this and I am sure it works.
, dockedItems: [{
xtype:'searchfield'
, name: "searchfield"
, placeHolder: 'Search Patient'
, id: 'searchPat'
, listeners: {
keyup: function(me,e){
var searchData = me.getValue();
Ext.Ajax.request({
url:'your data url'
, params:{
filter: searchData
}
, scope: this
, success: function(res){
var rec = Ext.decode(res.responseText);
var def = typeof (rec.success);
if(def != "undefined" ){
this.store.removeAll();
this.store.loadData(rec.patients);
}
}
, failure:function(res){
console.log(res);
}
})
}
, scope: this
}

Extjs 4 How to get id of parent Component?

I have multiple fieldset. And have Button inside each fieldset in Extjs 4.
I want to get fieldset id on the button click event, so that i can know from which fieldset the button was clicked
How do i get this?
{
xtype:'fieldset',
id:'fs1',
items:[{
xtype:'button',
id:'b1',
handler:function(){
// here i want to get fieldset's id because because fieldset and button were added dynamically.
}
}]
}
Thanks,
Kunal
Actual Code:
Ext.define('My.Group',{
xtype : 'fieldset',
config: {
title:'Group' + i.toString(),
id : '_group' + i.toString()
},
constructor: function(config) {
this.initConfig(config);
return this;
},
collapsible : true,
frame : false,
boder : false,
items : [ {
xtype : 'button',
text : 'Add KeyWord',
id: 'btn',
width : 100,
handler : function(button,event) {
var fieldset = button.findParentByType('fieldset');
var fieldsetsID = fieldset.getId();
console.log(fieldset);
Ext.getCmp(fieldsetId).insert(2, rangeField);
Ext.getCmp(fieldsetsID).doLayout();
}
}, {
xtype : 'button',
text : 'Add Range Type',
width : 100
} ]
});
and i am calling this function on button click
handler : function() {
i=i+1;
var group = new My.Group({
title:'Group' + i.toString(),
id : '_group' + i.toString()
});
console.log(group);
Ext.getCmp('_aspanel').insert(i, group);
Ext.getCmp('_aspanel').doLayout();
I've implemented handler properly.
{
xtype:'fieldset',
id:'fs1',
items:[{
xtype:'button',
id:'b1',
handler:function(btn){
// Retrieve fieldset.
var fieldset = btn.up('fieldset');
// Retrieve Id of fieldset.
var fieldsetId = fieldset.getId();
}
}]
}
In that case try this:
button.up("[xtype='fieldset']")
Ext.onReady(function() {
var panel = Ext.create('Ext.panel.Panel', {
items: {
xtype:'fieldset',
id:'fs1',
items:[{
xtype:'button',
id:'b1',
handler:function(b,e){
var fieldset = b.findParentByType('fieldset');
var fieldsetID = fieldset.getId();
console.log(fieldsetID);
}
}]
},
renderTo: document.body
});
});
Notice, that once you have fieldset variable, you can actually add items to this container directly, without need to use its ID

sencha touch search form

I really hope someone can help me, It seems like this should be obvious but sencha documentation isn't very easy to read and incomplete. I am trying to build a search form but it doesnt seem to take the store or the url and I can't figure out how to add parameters like page? Can anyone help? This code just produces Failed to load resource: null.
var searchField = new Ext.form.Search({
value:'Search',
url: 'someurl',
store: this.data_store,
cls:'searchfield',
listeners: {
focus: function(){ searchField.setValue(''); },
blur: function(){ if( searchField.getValue()=='' ){ searchField.setValue('Search'); } },
success: function(e){
console.log(e);
}
}
});
this.dockedItems = [ searchField ];
Ext.form.FormPanel doesn't take a Ext.data.Store or Ext.data.Model directly but does deal with Instances of Ext.data.Model. Lets say you have the following model:
Ext.regModel('MyForm', {
fields: [{name: 'id', type: 'int'},'name','description']
proxy: {
type: 'ajax',
url: 'url_to_load_and_save_form'
}
})
Now your form definition would look something like this:
Ext.form.MyForm = Ext.extend(Ext.form.FormPanel, {
record : null,
model: 'MyForm',
items: [{
xtype: 'hidden',
name: 'id'
},{
xtype: 'textfield',
name: 'name',
allowBlank: false
},{
xtype: 'textarea',
name: 'description'
}],
submit : function(){
var record = this.getRecord() || Ext.ModelMgr.create({}, this.model);
this.updateRecord(record , true);
record.save({
scope: this,
success : function(record, opts){
this.fireEvent('saved', record);
},
callback: function(){
this.setLoading(false);
}
});
}
});
Ext.reg('MyForm',Ext.form.MyForm);
Of course you should add in some validations and a button to actually call the Ext.form.MyForm.submit method.