PDA

View Full Version : MVC : How do I save checkbox values or responses in to a Store?



anthony70125
19 Mar 2015, 7:51 AM
I have a toolbar with several button menus. here is one of the button's menu.

I want to collect the checked values and checkbox name and save them to a store.



{
xtype: 'checkboxgroup',
id: 'cbg',
vertical: true,
layout: 'column',
defaultType: 'container',
items:
[
{
columnWidth: 1,
items:
[
{
xtype: 'checkboxfield', boxLabel: 'All', name: 'all_dataType', id: 'all_dataType', inputValue: 'true',
scope: this,
handler: function(field, value)
{
if (value)
{
Ext.getCmp('bathydatatype').setValue(1);
Ext.getCmp('globaldatatype').setValue(1);
Ext.getCmp('topodatatype').setValue(1);
}
else
{
Ext.getCmp('bathydatatype').setValue(0);
Ext.getCmp('globaldatatype').setValue(0);
Ext.getCmp('topodatatype').setValue(0);
};
}// end handler
},
{xtype: 'checkboxfield', boxLabel: 'Bathymetrics', id: 'bathydatatype', name: 'bathymetrics_dataType', inputValue: 'true'},
{xtype: 'checkboxfield', boxLabel: 'Global', id: 'globaldatatype', name: 'global_dataType', inputValue: 'true'},
{xtype: 'checkboxfield', boxLabel: 'Topography', id: 'topodatatype', name: 'topography_dataType', inputValue: 'true'}
]
}




Ext.define('GoApp.store.ds',
{
extend: 'Ext.data.Store',

// cross domain protocols are required
// requiring an object without using that object, fails the script
requires: ['Ext.data.proxy.JsonP'],
model: 'GoApp.model.Post',
pageSize: 10,
autoLoad: true,
autoSync: true,

// server communication
proxy:
{
type: 'jsonp',
callbackkey: 'results',
url: 'http://172.18.100.96/capstone/locate/return/',
reader:
{
type: 'json',
root: 'results'
}
}
});

Ext.define("GoApp.model.Post",
{
extend: 'Ext.data.Model',

requires: ['Ext.data.Field'],

fields:
[

{ name: 'dataType', type: 'auto' }
]
});

joel.watson
21 Mar 2015, 8:37 AM
Hi--

I've included a Fiddle (below) which demonstrates one approach. The basic idea is that I add a "ref" to the controller to provide easy access to the checkbox group (and avoid using a hard-coded "id"). In the controller, I added a listener for the "Save" button, and in the handler I do the following:

Get reference to checkbox group and target store
Retrieve checked items via getChecked()
Loop over checked items and add data to store
Of course, you don't necessarily need the controller...I just did that because your subject line mentioned "MVC".

I hope that helps!
Thanks
Joel

k23