Pick event not triggered for select field picker,while importing sencha-touch/base scss - sencha-touch-2

I am having one select field and want to handle select field picker events manually. Following code for selectfield :
{
xtype: 'selectfield',
label: 'Choose one',
name:'abcd',
usePicker:true,
options: [
{text: 'First Option', value: 'first'},
{text: 'Second Option', value: 'second'},
{text: 'Third Option', value: 'third'}
],
defaultPhonePickerConfig: {
hideOnMaskTap: true,
listeners: {
change: function(ths, val) {
console.log('change event called');
},
pick: function(ths, The, slot) {
console.log('pick event called');
PICKER_CONFIG = null;
if (PICKER_CONFIG != true) {
if (The[slot.getName()] != undefined && The[slot.getName()] != null && The[slot.getName()] != "") {
// Ext.getCmp('contractList').setValue(The[slot.getName()]);
ths.fireEvent('change', ths, The);
ths.hide();
}
}
},
cancel: function() {
console.log('cancel called');
PICKER_CONFIG = true;
},
show:function(){
console.log('show called');
}
}
},
pick is not getting called because i am using base css .
Here is my app.scss
#import 'sencha-touch/base';
But its working if i am using sencha-touch default and default/all css
like:
#import 'sencha-touch/default';
#import 'sencha-touch/default/all;
but, i don't want to use it
Is there any way to get that pick by using sencha-touch/base css.

hmm...
Can you tell me from where you get "pick" event ?
And what it supposed to do ?
I'm guessing that its doing the same thing as "change".
And how do you know its because you are using base css ?
from what I read the base css is sencha will be using bare minimum styling for components to work and the rest will be up to user. so there should be no effect on event components behaviour.

This is what i wrote to set Picker in SelectField:
{
xtype: 'selectfield',
usePicker: true,
displayField: 'text',
valueField: 'value',
options: [
{ text: 'Choose Dosage', value: 'default' },
],
defaultPhonePickerConfig : {
listeners: {
change: function(thePicker, newValue, oldValue) {
//check if custom variable has been set to false
if (newValue.slotsNumeric != null && newValue.slotsDecimal != null) {
var total = newValue.slotsNumeric + newValue.slotsDecimal;
// set the select field to show the correct selected value!!
var DecimalPicker = Ext.ComponentQuery.query('selectfield')[0];
DecimalPicker.setOptions({
text: total,
value: total
});
}
},
},
useTitles: true,
hideOnMaskTap: true,
slots: [
{
name : 'slotsNumeric',
title : 'Numeric',
align: 'center',
data : [
{text: '0', value: 0},
{text: '1', value: 1},
{text: '2', value: 2},
{text: '3', value: 3},
{text: '4', value: 4},
{text: '5', value: 5},
{text: '6', value: 6},
{text: '7', value: 7},
{text: '8', value: 8},
{text: '9', value: 9},
]
},
{
name : 'slotsDecimal',
title : 'Decimal',
align: 'center',
data : [
{text: '.0', value: .0},
{text: '.1', value: .1},
{text: '.2', value: .2},
{text: '.3', value: .3},
{text: '.4', value: .4},
{text: '.5', value: .5},
{text: '.6', value: .6},
{text: '.7', value: .7},
{text: '.8', value: .8},
{text: '.9', value: .9},
]
}
]
}
}

Related

getting index value 0 from dataview any list itemtap from sencha touch

I am unable to get index value form the dataview:
{
xtype: 'list',
itemId: 'catList',
store: 'CategoryStore',
scrollable: false,
layout: 'fit',
itemHeight: 20,
itemTpl: [
'<div>',
'<tpl for="data">',
'<span >{category_name}</span> ',
'</tpl>',
'</div>'],
listeners: {
'itemtap': function(list, index, target, record, e, eOpts){
console.log(record.get('cat_id'));
}
}
}
Edited:
If i put data static on store it works fine but it does not work while getting data from server:
it works like as displayed on list:
{
xtype: 'list',
itemId: 'catList',
scrollable: false,
data: [
{ category_name: 'A', cat_id: 1},
{ category_name: 'B', cat_id: 2},
{ category_name: 'C', cat_id: 3},
{ category_name: 'D', cat_id: 4},
{ category_name: 'E', cat_id: 5},
],
loadingText: "Loading Words...",
emptyText: '<div>{message}</div>',
autoLoad:true,
itemTpl:[
'<tpl for=".">',
'<span >{category_name}</span> ',
'</tpl>',
]
},
Here, I tap many times on different row but only gets index 0, why is this? why am i not getting different index value while tapping different row of list item;
My JSON
I tried and working perfectly for me, Let me share what i did.
Model
Ext.define('Myapp.model.Category', {
extend: 'Ext.data.Model',
config: {
fields: [
{ name: 'cat_id', type: 'integer' },
{ name: 'category_name', type: 'string' },
{ name: 'created_date', type: 'string' },
{ name: 'order', type: 'integer' },
{ name: 'status', type: 'integer' },
{ name: 'deleted', type: 'integer' },
{ name: 'type', type: 'integer' }
]
}
});
Store
Ext.define('Myapp.store.Category', {
extend: 'Ext.data.Store',
requires: [
'Myapp.model.Category'
],
config: {
storeId: 'category',
model: "Myapp.model.Category",
proxy: {
type: "ajax",
url : "http://alucio.com.np/trunk/dev/sillydic/admin/api/word/categories/SDSILLYTOKEN/650773253e7f157a93c53d47a866204dedc7c363?_dc=1376475408437&page=1&start=0&limit=25",
reader: {
type: "json",
rootProperty: "data"
}
},
autoLoad: true
}
});
List
{
xtype: 'list',
itemId: 'catList',
store: Ext.create('Myapp.store.Category'),
layout: 'fit',
itemHeight: 20,
itemTpl: [
'<div>',
'{category_name}',
'</div>'],
listeners: {
itemtap: function(list, index, target, record, e, eOpts){
console.log(record.get('cat_id'));
}
}
}
Output
As you can see itemtap function also printing correct cat_id
UPDATE
Based on your comment
{
xtype :'panel',
items : [{
xtype : 'toolbar',
itemId: 'categoryName' // Give itemId
},
{
xtype: 'list',
itemId: 'catList',
height : '100%',
store: Ext.create('GoodNews.store.Category'),
layout: 'fit',
itemHeight: 20,
itemTpl: [
'<div>',
'{category_name}',
'</div>'],
listeners: {
itemtap: function(list, index, target, record, e, eOpts){
var catId = record.get('cat_id');
var categoryName = record.get('category_name');
// Set the title like this
this.getParent().getComponent('categoryName').setTitle(categoryName);
}
}
}]
}
I don't really know what's wrong with your code as I tested it and it worked fine. However, a few things are wrong.
You do not need the for loop in your itemTpl as "itemTpl" is already
iterating in you data array for you. You would need it if you were
using just "tpl".
Avoid to have your listeners in your view. Instead,
get a reference to your list in your controller, and set the
listeners there. This is bad practise and it breaks the NVC pattern.
Here is a small version that works on my te4st application:
{
xtype: 'list',
itemId: 'catList',
scrollable: false,
data: [
{ category_name: 'A', cat_id: 1},
{ category_name: 'B', cat_id: 2},
{ category_name: 'C', cat_id: 3},
{ category_name: 'D', cat_id: 4},
{ category_name: 'E', cat_id: 5},
],
loadingText: "Loading Words...",
emptyText: '<div>{message}</div>',
autoLoad:true,
itemTpl: '{category_name}',
listeners: {
'itemtap': function(list, index, target, record, e, eOpts){
//TODO: whatever..
}
}
}

How to map hierarchical Json to ItemFileWriteStore?

I have Json data that has children elements. I need to bind the store to an editable grid and have the edits populated to the store.
The data tree does get populated into the ItemFileWriteStore. The datagrid displays only the parent data and none of the children data.
SAMPLE.TXT
{
"items": [
{
"profileId": "1",
"profileName": "ABC",
"profileType": "EmailProfile",
"profilePreferences": [
{
"profilePreferenceId": "1",
"displayText": "Bob",
"address": "primary#some.com"
},
{
"profilePreferenceId": "2",
"displayText": "Sally",
"address": "secondary#some.com"
},
{
"profilePreferenceId": "3",
"displayText": "Joe",
"address": "alternate#some.com"
}
]
}
]
}
javascript
var sampleLayout = [
[
{ field: 'profileName', name: 'profileName', width: '100px' },
{ field: 'profilePreferences.displayText', name: 'displayText', width: '100px' },
{ field: 'profilePreferences.address', name: 'address', width: '100px' }
]];
function populateGrid() {
var url = "sample.txt"; //Will be replaced with endpoint URL
dojo.xhrGet({
handleAs: 'json',
url: url,
error: function (e) {
alert("Error: " + e.message);
},
load: showJsonData
});
}
function showJsonData(response, ioArgs) {
var profileStore = new dojo.data.ItemFileWriteStore({
data: {
items: response.items
}
});
var sampleGrid = dijit.byId("sampleGrid");
sampleGrid.store = profileStore;
sampleGrid.startup();
}
you need to be using dojox.grid.TreeGrid or 'fake' the JSON to present every even row with a blank profileName. Two samples follows, one for TreeGrid another on DataGrid - not tested in working environment though.
Given Hierachial JSON:
{
identifier: 'id' // a good custom to make an id pr item, note spaces and odd chars are invalid
items: [{
id: '1',
profileName: 'Admin',
profilePreferences: [
{ id: '1_1', displayText: 'John Doe', address: 'Big Apple' }
{ id: '1_2', displayText: 'Jane Doe', address: 'Hollywood' }
]
}, {
id: '2',
profileName: 'Visitor',
profilePreferences: [
{ id: '2_1', displayText: 'Foo', address: 'Texas' }
{ id: '2_2', displayText: 'Bar', address: 'Indiana' }
]
}]
}
TreeGrid Structure:
{
cells: [
[
{ field: "profileName", name: "profileName", width: "100px" },
{ field: "profilePreferences",
children: [
{ field: "displayText" name: "displayText", width: "100px" },
{ field: "address" name: "address", width: "100px" }
]
]
]
}
reference: dojo docs
Given flattened 'fake-children' JSON:
{
identifier: 'id' // a good custom to make an id pr item, note spaces and odd chars are invalid
items: [{
id: '1',
profileName: 'Admin', preferenceText: '', preferenceAddr: ''
}, {
id: '2',
profileName: '', preferenceText: 'John', preferenceAddr: 'NY'
}, {
id: '3',
profileName: 'Visitor', preferenceText: '', preferenceAddr: ''
}, {
id: '4', // Not with '.' dot seperator like so
profileName: '', preference.Text: 'Jane Doe', preference.Addr: 'Hollywood'
} ]
DataGrid structure:
[[
{'name': 'Profilename', 'field': 'profileName', 'width': '100px'},
{'name': 'User name', 'field': 'preferenceText', 'width': '100px'},
{'name': 'Address', 'field': 'preferenceAddr', 'width': '200px'}
]]
reference dojo docs

Sencha touche form validation

I am creating my first app with sencha touch.
I have a problem with form validation.
This is the form:
var form = new Ext.form.FormPanel({
title: 'Activity',
items: [{
xtype: 'fieldset',
items: [{
xtype: 'textfield',
name : 'sector',
label: 'Sector',
required: true
},
{
xtype: 'selectfield',
name : 'city',
label: 'City',
options: [
{
text: '*',
value: '*'
},
{
text: 'First Option',
value: 'first'
},
{
text: 'Second Option',
value: 'second'
},
{
text: 'Third Option',
value: 'third'
}]
},
{
xtype: 'textfield',
name : 'nation',
label: 'Nation',
required: true
},
{
xtype: 'toolbar',
docked: 'bottom',
layout: {
pack: 'center'
},
items: [{
xtype: 'button',
text: 'Cerca',
handler: function() {
formSettori.submit({
url: 'book.php',
method: 'GET',
success: function() {
Ext.Msg.alert('OK');
},
failure: function() {
Ext.Msg.alert('NO');
}
});
}
},
{
xtype: 'button',
text: 'Reset',
handler: function() {
form.reset();
}
}]
}]
}]
});
the form has only three fields:
-activities
-city​​
-nation
all fields are required.
activities and the nation must not be empty, while the city should not be equal to *
how do I control the fields?
thank you!
There is not built in way to do form validation. You must do it yourself.
The easiest way is to use the private Ext.form.Panel method getFields to loop through each of the fields and ensure they are not empty.
var fields = form.getFields(),
field, name, isEmpty;
for (name in fields) {
field = fields[name];
isEmpty = (!field.getValue() || field.getValue() == "");
if (isEmpty) {
field.addCls('x-invalid');
} else {
field.removeCls('x-invalid');
}
}
If the field is empty, then we add the x-invalid class (so you can style it).

Confirm password validator ExtJs 4

I want to add a simple validator to verify that "password" and "confirm password" are equal, here is the code :
Ext.apply('Ext.form.VTypes',{
password : function(val, field) {
if (field.initialPassField) {
var pwd = Ext.getCmp(field.initialPassField);
return (val == pwd.getValue());
}
return true;
},
passwordText : 'Passwords do not match'
});
var genders = Ext.create('Ext.data.Store', {
fields: ['abbr', 'name'],
data : [
{"abbr":"AL", "name":"Male"},
{"abbr":"AK", "name":"Female"}
]
});
//****************************************
Ext.define('AM.view.user.Inscription', {
extend: 'Ext.form.Panel',
alias: 'widget.inscription',
title: 'Formulaire',
fieldDefaults: {
labelAlign: 'right',
msgTarget: 'side'
},
items: [{
xtype: 'container',
anchor: '100%',
layout:'column',
items:[{
xtype:'textfield',
fieldLabel: 'First Name',
name: 'first',
allowBlank:false,
anchor:'40%',
//maxLength : '10'
},{
xtype:'textfield',
fieldLabel: 'Last Name',
name: 'last',
allowBlank:false,
anchor:'40%'
},{
xtype:'textfield',
inputType: 'password',
fieldLabel:'Password',
name:'pass',
id : 'pass',
allowBlank:false,
anchor:'40%'
},{
xtype:'textfield',
inputType: 'password',
fieldLabel:'Confirm Password',
name:'confirmPass',
allowBlank:false,
vtype : 'password',
initialPassField : 'pass',
//autoRender : true,
anchor:'40%'
}]
},{
xtype: 'container',
columnWidth:.5,
layout: 'anchor',
items: [{
xty pe:'combobox',
fieldLabel: 'Sexe',
store: genders,
queryMode: 'local',
displayField: 'name',
allowBlank : false,
name: 'gender',
editable : false,
anchor:'30%',
},{
xtype:'textfield',
fieldLabel: 'N° Téléphone',
name: 'phone',
allowBlank:false,
anchor:'40%'
}]
}]
}],
buttons: [{
text: 'Save'
},{
text: 'Reset'
},{
text: 'Cancel'
}]
});
whene I start write in the confirm password textfield I get this in chrome developer tool :
Uncaught TypeError: Object [object Object] has no method 'password'
can someone tell me what I miss here ? thank you at advance.
UPDATE
the application is an MVC application and this file (the code above) is in View folder, and I'm calling this view in the app.js like this :
Ext.require([
'Ext.panel.*',
'Ext.toolbar.*',
'Ext.button.*',
'Ext.container.ButtonGroup',
'Ext.layout.container.Table'
]);
Ext.application({
name: 'AM',
appFolder: 'app',
controllers: [
'Users'
],
launch: function() {
Ext.create('Ext.container.Viewport', {
layout : 'auto',
//layout : 'vbox',
renderTo: document.body,
items: [{
xtype : 'usertoolbar',
},{
html : '<br><br>'
},{
xtype: 'inscription',
},{
xtype: 'userlist',
}]
});
}
});
Also any notes about my methodology of structuring code are welcome
Change Ext.form.VTypes to Ext.form.field.VTypes in the first line. See if it helps.
Update: change your validate function to:
password : function(val, field) {
console.log(val, field);
if (field.initialPassField) {
var pwd = Ext.getCmp(field.initialPassField);
console.log(pwd);
return (val == pwd.getValue());
}
return true;
},
Change Ext.form.VTypes to Ext.form.field.VTypes. And try to remove quotes around 'Ext.form.field.VTypes'. E.g.:
Ext.apply(Ext.form.field.VTypes, {
password : function(val, field) {
if (field.initialPassField) {
var pwd = Ext.getCmp(field.initialPassField);
return (val == pwd.getValue());
}
return true;
}
The solution is to remove quotes around 'Ext.form.field.VTypes'
Ext.apply(Ext.form.field.VTypes, {
password: function (val, field) {
if (field.initialPassField) {
var pwd = Ext.getCmp(field.initialPassField);
return (val == pwd.getValue());
}
return true;
},
passwordText: 'Passwords do not match'
});

SenchaTouch Picker implementation?

i'm using SenchaTouch and would like to use their Picker for a UI component. I have this code:
var datePicker = new Ext.Picker({
slots: [
{
name : 'limit_speed',
useTitles: true,
title: 'Terminals',
data : [
{text: 'Terminalq 1', value: 1},
{text: 'Terminal 2', value: 2},
{text: 'Terminal 3', value: 3},
{text: 'Terminal 4', value: 4}
]
}
]
});
Does anyone know how to get an event handler to work on the doneButton??
Adding a function to the change event.
datePicker.on('change', function(){
// do some stuff
});
or
var datePicker = new Ext.Picker({
slots: [
{
name : 'limit_speed',
useTitles: true,
title: 'Terminals',
data : [
{text: 'Terminalq 1', value: 1},
{text: 'Terminal 2', value: 2},
{text: 'Terminal 3', value: 3},
{text: 'Terminal 4', value: 4}
]
}
],
listeners: {
change: {
element: 'el', //bind to the underlying el property on the panel
fn: function(){ console.log('click el'); }
}
}
});
you could also add it to the 'hide' event, depends if you care about the value or not.
if u want to take value of selected field u can use this code.
listeners: {
change: function(picker,button) {
selectedValue = picker.getValue()['limit_speed'];
console.log(selectedValue);
}
}
You can get the selected value of dynamically created datepicker
listeners: {
change: function(picker,selectedValue) {
console.log(selectedValue);
}
}