aligment of keypad buttons(numbers) - sencha-touch-2

I'm new to sencha touch.I wrote code for number keypad,but the buttons are displayed vertically.my code is
Ext.define("exercise.view.Numberplate",{
extend: "Ext.SegmentedButton",
requires:['Ext.Button'],
xtype:'Numberplate',
allowMultiple: true,
config: {
pack:'center',
centered:true,
height:30,
width:100,
xtype:'button',
items: [
{
xtype:'segmentedbutton',
allowDepress:true,
scroll:true,
//layout:'vbox',
items:[
{
text:'1',
width:100
},
{
text : '2',
width:100
},
{
text: '3',
width:100
}
]
},
{
xtype:'segmentedbutton',
//centered:true,
pack:'center',
items:[
/* {
centered:true,
html: [
'<br><br><br><br>'
].join("")
},*/
{
text:'4',
width:100
},
{
text:'5',
width:100
},
{
text:'6',
width:100
}
]
}
]
},
constructor: function() {
this.on({
scope: this,
delegate: 'button',
tap: 'tapHandler'
});
this.callParent(arguments);
},
tapHandler: function(button) {
alert(button.getText());
// this.setHtml("<span class=action>User tapped " + button.getText() + "</span>");
}
});
I tried ,but i didnt get this .I think it's easy but i don't know how to do this.can anyone help me.thanks in advance

Just add layout:vbox to your config:
Ext.define("exercise.view.Numberplate",{
extend: "Ext.SegmentedButton",
requires:['Ext.Button'],
xtype:'Numberplate',
allowMultiple: true,
config: {
layout: 'vbox', // Add right here
pack:'center',
centered:true,
height:30,
width:100,
xtype:'button',
items: [
{
xtype:'segmentedbutton',
allowDepress:true,
scroll:true,
//layout:'vbox',
items:[
{
text:'1',
width:100
},
{
text : '2',
width:100
},
{
text: '3',
width:100
}
]
},
{
xtype:'segmentedbutton',
//centered:true,
pack:'center',
items:[
/* {
centered:true,
html: [
'<br><br><br><br>'
].join("")
},*/
{
text:'4',
width:100
},
{
text:'5',
width:100
},
{
text:'6',
width:100
}
]
}
]
},
constructor: function() {
this.on({
scope: this,
delegate: 'button',
tap: 'tapHandler'
});
this.callParent(arguments);
},
tapHandler: function(button) {
alert(button.getText());
// this.setHtml("<span class=action>User tapped " + button.getText() + "</span>");
}
});
Hope it helps :)

Related

How to change view in Sencha Touch 2 using buttons?

I'm writing a Sencha Touch 2 application and I've got a problem with switching views. I've got two views (LoginPanel and RegisterPanel) and I want to switch from LoginPanel to RegisterPanel by clicking a button. I want to use "makeAccount" button to go to the RegisterPanel View. I've tried many tricks, but alas no one work. Here's my codes:
app.js
Ext.application({
name: 'kody2',
requires: [
'Ext.MessageBox'
],
controllers: [
'Main'
],
views: [
'HomeContainer',
'LoginPanel',
'Produkty',
'Start',
'SkanujKod',
'Opcje',
'KatalogPDF',
'RegisterPanel',
'SimpleProduct',
'ForgotPassword'
],
viewport: {
layout: {
type: 'card',
animation: {
type: 'fade',
direction: 'left',
duration: 300
}
}
},
icon: {
'57': 'resources/icons/Icon.png',
'72': 'resources/icons/Icon~ipad.png',
'114': 'resources/icons/Icon#2x.png',
'144': 'resources/icons/Icon~ipad#2x.png'
},
isIconPrecomposed: true,
startupImage: {
'320x460': 'resources/startup/320x460.jpg',
'640x920': 'resources/startup/640x920.png',
'768x1004': 'resources/startup/768x1004.png',
'748x1024': 'resources/startup/748x1024.png',
'1536x2008': 'resources/startup/1536x2008.png',
'1496x2048': 'resources/startup/1496x2048.png'
},
launch: function() {
// Destroy the #appLoadingIndicator element
Ext.fly('appLoadingIndicator').destroy();
// Initialize the main view
Ext.Viewport.add(Ext.create('kody2.view.HomeContainer'));
},
onUpdated: function() {
Ext.Msg.confirm(
"Application Update",
"This application has just successfully been updated to the latest version. Reload now?",
function(buttonId) {
if (buttonId === 'yes') {
window.location.reload();
}
}
);
}
});
LoginPanel.js
Ext.define('kody2.view.LoginPanel', {
extend: 'Ext.Panel',
xtype: 'loginpanel',
config: {
title: 'Twoje konto',
iconCls: 'user2',
styleHtmlContent: true,
scrollable: true,
items: [
{
xtype: 'fieldset',
id: 'formContent',
title: 'Zaloguj się',
items: [
{
xtype: 'emailfield',
name: 'login',
id: 'email_login',
label: 'Login'
},
{
xtype: 'passwordfield',
name: 'password',
id: 'form_password',
label: 'Hasło'
},
{
xtype: 'button',
text: 'Załóż konto',
id: 'makeAccount',
action: 'register'
},
{
xtype: 'button',
text: 'Zapomniałem hasło',
id: 'forgotPassword'
},
{
xtype: 'button',
text: 'Zaloguj',
id: 'logowanie'
}
]
}
]
}
});
and the Controller:
Ext.define('kody2.controller.Main', {
extend: 'Ext.app.Controller',
config: {
control: {
'button[action=register]': {
tap: 'myFunction'
}
}
},
myFunction: function() {
Ext.Viewport.add({
xtype: 'register'
});
}
});
Thanks for all help!
You just adding register view in viewport, But not setting it as active item.
Ext.Viewport.setActiveItem({xtype:'register'});
Above line will add register view in viewport and also sets as ActiveItem.
Update
Ext.define('kody2.controller.Main', {
extend: 'Ext.app.Controller',
config: {
control: {
'button[action=register]': {
tap: 'myFunction'
}
}
},
myFunction: function() {
Ext.Viewport.setActiveItem({ xtype: 'register' });
console.log(Ext.Viewport.getActiveItem().xtype);
}
});

Click event not getting registered from within a controller in ExtJS 4 MVC

My button click event subscribed in the controller is getting fired. Here is the code.
WebAppMasterController.js
Ext.define('P.e.w.controller.WebAppMasterController', {
extend: 'P.e.w.controller.IController',
views: [
'WebAppMasterView'
],
refs: [
{
ref: 'webAppView',
selector: 'WebAppMasterView'
}
],
init: function () {
this.control({
'WebAppMasterView': {
afterrender: this.viewafterrender
}
}, {
'button[action=save]': {
click: function () {
alert('dslksd');
}
}
}
},
viewafterrender: function (panel) {
alert();
}
});
IController extends "Ext.app.Controller".
In the above code, the "afterrender" event is getting triggered, but the button click event is not getting triggered.
The view: WebAppMasterView.js
Ext.define('P.e.w.view.WebAppMasterView', {
extend: 'P.w.l.Header',
alias: 'widget.WebAppMasterView',
constructor: function (config) {
var me = this;
me.centerregion = me.createCenterRegion(config);
Ext.applyIf(config, {
favoriteBar: true,
items: [me.centerregion],
menuWidth: 0
});
this.callParent([config]);
},
createBody: function () {
var me = this;
if (!me.controlPanel) {
me.controlPanel = Ext.create('Ext.Panel', {
layout: 'fit'
});
}
return me.controlPanel;
},
createCenterRegion: function (config) {
var me = this,
centerPanel = Ext.create('Ext.Panel', {
region: 'center',
layout: 'fit',
tbar: {
xtype: 'WorkRequestMenuBar',
id: 'workrequestmenubar'
},
defaults: {
border: false
},
items: [me.createBody()]
});
return centerPanel;
}
});
WorkRequestMenuBar.js
Ext.define('P.e.w.view.WorkRequestMenuBar', {
extend: 'Ext.Toolbar', alias: 'widget.WorkRequestMenuBar',
constructor: function (config) {
config = config || {};
Ext.apply(config, {
defaults: {
scale: 'large',
cls: 'x-btn-text-icon',
iconAlign: 'top'
},
items: [
{
text: 'NEW_WORK_REQUEST',
iconCls: 'menubar-createWorkRequest',
action: 'save'
},
{
text: 'OVERVIEW',
iconCls: 'menubar-overview'
}, '->', {
iconCls: 'icon-biggerHelp',
width: 80,
text: 'HELP'
}
]
});
this.callParent([config]);
}
});
You have several issues.
1st. there is a syntax error in your controller
this.control({
'WebAppMasterView': {
afterrender: this.viewafterrender
}
},
{
'button[action=save]': {
click: function () {
alert('dslksd');
}
}
}
//missing --> );
},
2nd. The toolbar config method should be initComponent method instead.

I need help in Sencha Calculator working Real Time

am trying to build a calculator that binds data in real time without the user pressing the calculate button. so far i can get my application to work but the user has to hit on the calculate button to perform the calculation which is not what i want.
My problem now is how can i make my calculator to work on real time meaning that once the first, second and third text-fields are filled, the fourth text-field will auto generate the answer without the calculation button being pressed. 1 + 1 + 1 = (3) the 3 will be auto generated in real time once the first 3 text-fields are filled. below are my codes so far:
Ext.define("ikhlas.view.login", {
extend: 'Ext.Panel',
xtype: 'loginpanel',
config:{
title: 'Login',
iconCls: 'more',
styleHtmlContent: true,
layout:{
type: 'vbox',
},
items: [
{
xtype: 'container',
iconCls: 'add',
items: [
{
xtype: 'textfield',
name: 'email',
id: 'txtField1',
placeHolder: 'Sum 1'
},
{
xtype: 'spacer',
height: 10,
},
{
xtype: 'textfield',
name: 'password',
id: 'txtField2',
placeHolder: 'Sum 2'
},
{
xtype: 'spacer',
height: 10,
},
{
xtype: 'textfield',
name: 'password',
id: 'txtField3',
placeHolder: 'Sum 3'
},
{
xtype: 'spacer',
height: 10,
},
{
xtype: 'textfield',
id: 'txtField4',
name: 'password',
placeHolder: 'Sum 4'
},
]},
{
xtype: 'button',
text: 'Calculate',
ui: 'confirm',
width: '30%',
height: '6%',
flex: 1,
left: '55%',
top: '65%',
action: 'submitBtn'
},
]}
});
And my Controller looks like this:
Ext.define('ikhlas.controller.SubmitController',{
extend: 'Ext.app.Controller',
config:{
refs:{
submitBtn: '#submitBtn',
txtField1: '#txtField1',
txtField2: '#txtField2',
txtField3: '#txtField3',
txtField4: '#txtField4'
},
control:{
'button[action=submitBtn]':{
tap :'submitbutton'
}
}
},
submitbutton:function(){
var value1 = Ext.getCmp('txtField1').getValue();
var value2 = Ext.getCmp('txtField2').getValue();
var value3 = Ext.getCmp('txtField3').getValue();
var value4;
value4 = value1 * value2 * value3;
Ext.getCmp('txtField4').setValue(value4);
}
});
So far the app is working fine with the code giving, but i need a real time calculation that's my objective. Hope someone can help out.
My store and My model are all empty for now.
I haven´t tried it myself, but I think you have to listen to the changeevent of your textfields and whenever a value changes, you have to recalculate the value.
So for every of your input textfields, add this to your controller:
control: {
'button[action=submitBtn]': {
tap: 'submitbutton'
},
// this should call your submitbutton function which calculates the values
// every time the value of textfield1 changes
txtField1: {
change: 'submitbutton',
}
}
A Simple caculator
Ext.define('Calc.view.Main', {
extend: 'Ext.form.Panel',
fullscreen:true,
config: {
items: [
{
layout:'vbox',
style:'background-color:blue',
flex:1,
items:[
{
xtype:'textareafield',
name:'display',
style:'border:5px inset blue',
id:'display',
value:"0"
}
]
},
{
layout:'hbox',
style:'background-color:#cccccc',
flex:1,
items :[
{
xtype:'button',
text:'1',
style:'border:5px inset blue',
flex:1,
ui:'confirm',
handler: function() {
var num=Ext.getCmp('display').getValue();
if(num==0) {
Ext.getCmp('display').setValue("1");
}
else
{
num=num+"1";
Ext.getCmp('display').setValue(num);
}
console.log(num);
}
},
{
xtype:'button',
text:'2',
flex:1,
style:'border:5px inset blue',
ui:'confirm',
handler: function() {
console.log("print 2");
var num=Ext.getCmp('display').getValue();
if(num==0) {
Ext.getCmp('display').setValue("2");
}
else
{
num=num+"2";
Ext.getCmp('display').setValue(num);
}
console.log(num);
/*Ext.getCmp('display').setValue("2");
var num=Ext.getCmp('display').getValue();
num=num*10+1;
Ext.getCmp('display').setValue(num);
console.log(num);*/
}
},
{
xtype:'button',
text:'3',
style:'border:5px inset blue',
flex:1,
ui:'confirm',
handler: function() {
console.log("print 3");
var num=Ext.getCmp('display').getValue();
if(num==0) {
Ext.getCmp('display').setValue("3");
}
else
{
num=num+"3";
Ext.getCmp('display').setValue(num);
}
console.log(num);
}
}
]
},
{
layout:'hbox',
style:'background-color:#909090',
flex:1,
items:[
{
xtype:'button',
text:'4',
style:'border:5px inset blue',
flex:1,
ui:'confirm',
handler: function() {
console.log("print 4");
var num=Ext.getCmp('display').getValue();
if(num==0) {
Ext.getCmp('display').setValue("4");
}
else
{
num=num+"4";
Ext.getCmp('display').setValue(num);
console.log(num);
}
}
},
{
xtype:'button',
text:'5',
flex:1,
style:'border:5px inset blue',
ui:'confirm',
handler: function() {
console.log("print 5");
var num=Ext.getCmp('display').getValue();
if(num==0) {
Ext.getCmp('display').setValue("5");
}
else
{
num=num+"5";
Ext.getCmp('display').setValue(num);
}
console.log(num);
}
},
{
xtype:'button',
text:'6',
flex:1,
style:'border:5px inset blue',
ui:'confirm',
handler: function() {
console.log("print 6");
var num=Ext.getCmp('display').getValue();
if(num==0) {
Ext.getCmp('display').setValue("6");
}
else
{
num=num+"6";
Ext.getCmp('display').setValue(num);
}
console.log(num);
}
}
]
},
{
layout:'hbox',
style:'background-color:#A0A0A0',
flex:1,
items:[
{
xtype:'button',
text:'7',
style:'border:5px inset blue',
flex:1,
ui:'confirm',
handler: function() {
console.log("print 7");
var num=Ext.getCmp('display').getValue();
if(num==0) {
Ext.getCmp('display').setValue("7");
}
else
{
num=num+"7";
Ext.getCmp('display').setValue(num);
}
console.log(num);
}
},
{
xtype:'button',
text:'8',
style:'border:5px inset blue',
flex:1,
ui:'confirm',
handler: function() {
console.log("print 8");
var num=Ext.getCmp('display').getValue();
if(num==0) {
Ext.getCmp('display').setValue("8");
}
else
{
num=num+"8";
Ext.getCmp('display').setValue(num);
console.log(num);
}
}
},
{
xtype:'button',
text:'9',
style:'border:5px inset blue',
flex:1,
ui:'confirm',
handler: function() {
console.log("print 9");
var num=Ext.getCmp('display').getValue();
if(num==0) {
Ext.getCmp('display').setValue("9");
}
else
{
num=num+"9";
Ext.getCmp('display').setValue(num);
}
console.log(num);
}
}
]
},
{
layout:'hbox',
style:'background-color:#808080',
flex:1,
items: [
{
xtype:'button',
text:'+',
style:'border:5px inset blue',
flex:1,
ui:'confirm',
handler: function() {
var num = new Array();
num=Ext.getCmp('display').getValue();
var len=num.length;
console.log(len);
var sub=num.substr(len-1,len);
console.log(sub);
if(sub!= "+" && sub!="-" && sub!="*" &&sub!="/")
{
num=num+"+";
Ext.getCmp('display').setValue(num);
}
console.log("print +");
}
},
{
xtype:'button',
text:'0',
flex:1,
style:'border:5px inset blue',
ui:'confirm',
handler: function() {
console.log("print 0");
var num=Ext.getCmp('display').getValue();
if(num==0) {
num=num+"0";
Ext.getCmp('display').setValue(num);
}
else
{
num=num+"0";
Ext.getCmp('display').setValue(num);
console.log(num);
}
}
},
{
xtype:'button',
text:'=',
flex:1,
style:'border:5px inset blue',
ui:'confirm',
handler: function() {
console.log("print =");
var exp=new Array();
exp=Ext.getCmp('display').getValue();
var len=exp.length;
var sub=exp.substr(len-1,len);
console.log(sub);
if(sub!= "+" && sub!="-" && sub!="*" && sub!="/")
{
console.log(eval(exp));
Ext.getCmp('display').setValue(eval(exp));
}
}
}
]
},
{
layout:'hbox',
style:'background-color:#2FAA96',
flex:1,
items: [
{
xtype:'button',
text:'-',
flex:1,
style:'border:5px inset blue',
ui:'confirm',
handler: function() {
console.log("print -");
var num = new Array()
num=Ext.getCmp('display').getValue();
var len=num.length;
var sub=num.substr(len-1,len);
if(sub!= "+" && sub!="-" && sub!="*" &&sub!="/")
{
num=num+"-";
Ext.getCmp('display').setValue(num);
console.log("print -");
}
}
},
{
xtype:'button',
text:'*',
style:'border:5px inset blue',
flex:1,
ui:'confirm',
handler: function() {
console.log("print *");
var num = new Array()
num=Ext.getCmp('display').getValue();
var len=num.length;
var sub=num.substr(len-1,len);
if(sub!= "+" && sub!="-" && sub!="*" &&sub!="/")
{
num=num+"*";
Ext.getCmp('display').setValue(num);
console.log("print *");
}
}
},
{
xtype:'button',
text:'/',
style:'border:5px inset blue',
flex:1,
ui:'confirm',
handler: function() {
console.log("print /");
var num = new Array()
num=Ext.getCmp('display').getValue();
var len=num.length;
var sub=num.substr(len-1,len);
if(sub!= "+" && sub!="-" && sub!="*" &&sub!="/")
{
num=num+"/";
Ext.getCmp('display').setValue(num);
console.log("print /");
}
}
},
]
},
{
layout:'hbox',
flex:8,
style:'background-color:red',
items: [
{
xtype:'button',
text:'clear',
style:'border:5px inset blue',
flex:1,
ui:'small',
handler: function() {
var cl=Ext.getCmp('display').getValue();
cl="";
Ext.getCmp('display').setValue(cl);
}
},
{
xtype:'button',
text:'cancel',
flex:2,
ui:'back',
handler:function() {
var no= new Array();
no=Ext.getCmp('display').getValue();
var len=no.length;
var sub=no.slice(0,len-1)
console.log(sub);
Ext.getCmp('display').setValue(sub);
}
}
]
}
]
}
});

Create DataItem in Dataview Sencha Touch 2

I need create a dataview component with the following structure
Structure
I learned how to create simple text component, but this structure is more difficult.
I use this code, but is only the name field
Ext.define('DEMO.view.product.ListItem', {
extend: 'Ext.dataview.component.DataItem',
xtype: 'product-list-item',
config: {
cls: 'product-list-item',
dataMap: {
getName: {
setHtml: 'name'
}
},
name: {
cls: 'x-name',
flex: 1
},
layout: {
type: 'hbox',
align: 'left'
}
},
applyName: function(config){
return Ext.factory(config, Ext.Component, this.getName());
},
updateName: function(newName, oldName) {
if (newName) {
this.add(newName);
}
if (oldName) {
this.remove(oldName);
}
}
});
Just need to add the other components as the name. For example,
Ext.define('App.view.UserItem', {
extend: 'Ext.dataview.component.DataItem',
xtype: 'useritem',
config: {
cls: 'user-item',
firstName: { cls: 'first-name', flex: 1 },
lastName: { cls: 'last-name', flex: 2 },
layout: { type: 'hbox', align: 'center' },
dataMap: {
getFirstName: { setHtml: 'firstName' },
getLastName: { setHtml: 'lastName' }
}
},
applyFirstName: function(config) {
return Ext.factory(config, Ext.Component, this.getFirstName());
},
updateFirstName: function(newFirstName, oldFirstName) {
if(newFirstName) this.add(newFirstName);
if(oldFirstName) this.remove(oldFirstName);
},
applyLastName: function(config) {
return Ext.factory(config, Ext.Component, this.getLastName());
},
updateLastName: function(newLastName, oldLastName) {
if(newLastName) this.add(newLastName);
if(oldLastName) this.remove(oldLastName);
}
});
For more detail, please visit http://www.sencha.com/blog/dive-into-dataview-with-sencha-touch-2-beta-2/

Cards not displaying in Sencha Touch application

I am using Sencha Touch 1.1. The following code makes up the view:
truApp.views.IncidentParentView = Ext.extend(Ext.Panel, {
layout: {
type: 'hbox',
align: 'top'
},
initComponent: function () {
this.sectionStore = Ext.StoreMgr.get(TrafficResponse.Stores.IncidentSections);
this.topToolbar = new Ext.Toolbar({
items: [
{
text: 'Cancel',
ui: 'back',
handler: function() {
Ext.dispatch({
controller: truApp.controllers.incidentController,
action: 'cancel'
});
}
},
{
xtype: 'spacer'
},
{
text: 'Submit',
ui: 'confirm',
handler: function() {
Ext.dispatch({
controller: truApp.controllers.incidentController,
action: 'submit'
});
}
}
]
});
this.dockedItems = [ this.topToolbar ];
this.items = [
{
flex: 1,
dockedItems: [
{
xtype: 'toolbar',
title: 'Sections',
ui: 'light'
}
],
items: [
{
xtype: 'list',
store: this.sectionStore,
scroll: false,
itemTpl: '{Description}',
listeners: {
itemTap: function(dataView, index, item, e) {
var record = dataView.store.getAt(index);
truApp.views.incidentParentView.getComponent('incidentCardPanel').setActiveItem(
index,
{ type: 'slide', direction: 'left' }
);
},
afterrender: function(dataView) {
dataView.getSelectionModel().select(0, false, false);
truApp.views.incidentParentView.getComponent('incidentCardPanel').setActiveItem(
0,
{ type: 'slide', direction: 'left' }
);
}
},
onItemDisclosure: true
}
]
},
{
flex: 3,
id: 'incidentCardPanel',
xtype: 'panel',
layout: 'card',
items: [
{
html: 'card 1'
},
{
html: 'card 2'
},
{
html: 'card 3'
},
{
html: 'card 4'
},
{
html: 'card 5'
},
{
html: 'card 6'
}
]
}
];
truApp.views.IncidentParentView.superclass.initComponent.call(this);
}
});
When the 'card' layout is used, nothing is displayed. When 'vbox' is used, all 6 items - card 1 to card 6 are displayed.
Why are the items not displaying when using card layout?
try to add fullscreen: true to your card layout settings. Didn't test, but is my first guess