My View (MyFormPanel)
var controllers = Ext.define("MyApp.controller.formcontroller", {
extend: "Ext.app.Controller",
config: {
refs: {
username: "username"
},
},
launch: function () {
alert('Controller launched');
},
init: function () {
alert('Controller init');
},
myaction : function (options) {
alert('options');
var username = options.username;
this.render ({
xtype: 'MyATM',
username: username})}
});
var formPanel = Ext.create('Ext.form.Panel', {
fullscreen: true,
scrollable: 'vertical',
layout: {
align: 'center',
type: 'vbox'
},
items: [
{
xtype: 'toolbar',
docked: 'top',
title: 'Login Form'
},
{
xtype: 'fieldset',
items: [
{
xtype: 'fieldset',
title:'Enter user name & password',
defaults: {
required: true,
labelAlign: 'left',
labelWidth: '50%'
},
items: [
{
xtype: 'textfield',
name : 'username',
label: 'User Name',
allowBlank:false,
useClearIcon: true
}, {
xtype: 'passwordfield',
name : 'password',
label: 'Password',
allowBlank:false,
useClearIcon: false
},
{
xtype: 'checkboxfield',
required:false,
id: 'RememberMe',
name: 'RememberMe',
label: 'Remember Me',
labelWidth: '50%'
},
{
xtype: 'button',
ui: 'confirm-round',
text: 'Log In' ,
handler: function() {
//Ext.Msg.alert('Form Values', JSON.stringify(formPanel.getValues(), null, 2));
Ext.ControllerManager.get('formcontroller').ControllerMethod({myaction: myaction});
}
}
]
}],
}]
});
formPanel.add({
xtype: 'toolbar',
docked: 'bottom',
layout: { pack: 'center' },
});
My controller (FormController)
Ext.define("MyApp.controller.formcontroller", {
extend: "Ext.app.Controller",
config: {
refs: {
username: "username"
},
},
launch: function () {
alert('Controller launched');
},
init: function () {
alert('Controller init');
},
myaction : function (options) {
alert('options');
var username = options.username;
this.render ({
xtype: 'MyATM',
username: username})}
});
I am using Sencha touch2 with Phonegap 1.4 on android 2.3. When i try to move view to controller on Login button click on handler function to invoke controller , i am getting error , Ext.dispatch is not defined as function .
Tell me the actual way how to move view to controller and vice versa.
Thanks
Ext.dispatch is not the recommended way to use in Sencha Touch 2. It might be removed...
Anyway, the best way to listen to & handle events on your views from controllers is:
Ext.define("MyApp.controller.formcontroller", {
extend: "Ext.app.Controller",
config: {
refs: {
loginButton: "#login-button" // set an id for your login button and this ref works
},
control: {
loginButton: {
tap: 'handleLogin',
}
handle_login: function(){whatever you want to do here}
}
And in Architect...
a. you go to the button's config, and
b. search for Event Handlers, and
c. you press the [+] button on the right.
d. Add a "basic handler"
e. Choose the TAP event
f. Give it a name (onButtonSendTap or whatever)
g. press DONE
h. right mouse
i. Convert to action
j. Choose [New Controller] or an existing controller
k. If you chose new controller give it a name
and voilla, you have your handler in the controller.
And in Architect...
a. you go to the button's config, and
b. search for Event Bindings, and
c. you press the [+] button on the right.
d. Add a "basic handler"
e. Choose the TAP event
f. Give it a name (onButtonSendTap or whatever)
g. press DONE
h. right mouse
i. Convert to action
j. Choose [New Controller] or an existing controller
k. If you chose new controller give it a name
and voilla, you have your handler in the controller.
Related
I am trying to confirm not by typing the button but by replying verbally on an alert window. I have already installed alertController and speechRecognition but I don't know how to make them interact together. This is my code :
presentAlertConfirm() {
this.alertController
.create({
header: 'object detection,
message: 'Are you sure you want to confirm?',
buttons: [
{
text: 'NO',
role: 'cancel',
cssClass: 'secondary',
handler: (data) => {
this.statusConfirm = 'confirmation canceled';
},
},
{
text: 'SI',
handler: () => {
this.statusConfirm = 'confirm OK';
this.viewObjectDetail;
},
},
],
})
.then((confirmElement) => {
confirmElement.present();
});
}
I have just downloaded sencha touch 2.4 and created a test android app. I am able to compile and run the app on android 4+ without problems. However, when I try to run it on android 2.3, the app doesn't go past the app loader indicator and I logged the process no errors are being displayed. Following is the code:
Ext.application({
name: 'Voice',
requires: [
'Ext.MessageBox'
],
views: [
'Main'
],
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('Voice.view.Main'));
},
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();
}
}
);
}
});
and the main code:
Ext.define('Voice.view.Main', {
extend: 'Ext.tab.Panel',
xtype: 'main',
requires: [
'Ext.TitleBar',
'Ext.Video'
],
config: {
tabBarPosition: 'bottom',
items: [
{
title: 'Welcome',
iconCls: 'home',
scrollable: true,
items: [{
docked: 'top',
xtype: 'titlebar',
title: 'Welcome to Sencha Touch 2'
}]
},
{
title: 'Get Started',
iconCls: 'action',
items: [
{
docked: 'top',
xtype: 'titlebar',
title: 'Getting Started'
},
{
xtype: 'video',
url: 'http://av.vimeo.com/64284/137/87347327.mp4?token=1330978144_f9b698fea38cd408d52a2393240c896c',
posterUrl: 'http://b.vimeocdn.com/ts/261/062/261062119_640.jpg'
}
]
}
]
}
});
I think it must be a bug in the 2.4 sencha touch release
We also had the same issue and it seems that it is a bug introduced in Sencha Touch 2.4.
And the reason is the usage of bind() method which is a part of ECMAScript 5 not supported on android 2.3
So to fix it you can find the file touch\src\event\publisher\TouchGesture.js and replace the following lines
if (Ext.feature.has.Touch) {
// bind handlers that are only invoked when the browser has touchevents
me.onTargetTouchMove = me.onTargetTouchMove.bind(me);
me.onTargetTouchEnd = me.onTargetTouchEnd.bind(me);
}
with these
if (Ext.feature.has.Touch) {
// bind handlers that are only invoked when the browser has touchevents
me.onTargetTouchMove = Ext.Function.bind(me.onTargetTouchMove, me);
me.onTargetTouchEnd = Ext.Function.bind(me.onTargetTouchEnd, me);
}
This solution helped us to avoid the problem
Following is my Sencha code of a simple registration form:
xtype: 'fieldset',
items: [
{
name: 'name',
id: 'rename',
xtype: 'textfield',
placeHolder: 'Name*',
tabIndex: 1
},
{
name: 'emailfield',
id: 'reemailid',
xtype: 'emailfield',
placeHolder: 'email#example.com*',
tabIndex: 2
},
{
name: 'password',
id: 'repassword',
xtype: 'passwordfield',
placeHolder: 'Password*',
tabIndex: 3
},
{
name: 'confpassword',
id: 'reconfpassword',
xtype: 'passwordfield',
placeHolder: 'Confirm Password*',
tabIndex: 4
},
{
name: 'address',
id: 'readdress',
xtype: 'textareafield',
placeHolder: 'Address*',
tabIndex: 5
},
{
name: 'dob',
id: 'redob',
placeHolder: 'Date Of Birth',
xtype: 'datepickerfield',
destroyPickerOnHide: true,
picker: {
yearFrom: 1960
},
tabIndex: 6
}
]
When I am filling up the form in Android keyboard there is a 'Go' button in bottom right corner of the android keyboard, which helps us to submit the form. But I want a 'Next' button which will take me to the next field, I mean if I filled the name and press the 'Next' button on Android keyboard then it should take me to email.
The action event is triggered on a textfield whenever the "Return" or "Go" key is pressed. You should leverage that to call the focus method on the next field.
Something like this will work on Android, didn't test it on iOS though
Ext.define('Fiddle.view.Main', {
extend: 'Ext.Container',
config: {
fullscreen: true,
styleHtmlContent: true,
items: [
{
xtype: 'textfield',
label: 'First field',
listeners: {
action: function() {
Ext.getCmp('field_2').focus();
}
}
},
{
id: 'field_2',
xtype: 'textfield',
label: 'Second field'
}
]
}
});
Working example at: https://fiddle.sencha.com/?fiddle=b3o#fiddle/b3o
[EDIT]
Previous solution remains valid but I found this linked question:
How to change the Android softkey keyboard "Go" button to "Next".
This is done on the native Android project and modifies the behavior of the "Go" button application wide. Check it out.
In my ST2-app i create a panel which contains a carousel-element.
This carousel has to be filled dynamically with images from my store.
My problem is that the code shown below works fine in Chrome, but when i package my app and install it on my Galaxy S2, the initialize-event wont fire.
Has anyone a suggestion what could be the problem here?
I thought the browser androis is using is based on googles chrome-browser, so it should work the same.
Code:
createPanelBalloonSelect: function() {
panelBalloonSelect = Ext.Viewport.add({
xtype: 'panel',
centered: true,
styleHtmlContent: true,
width: '90%',
height: '70%',
modal: true,
scope: this,
layout: {
type: 'vbox',
align: 'stretch'
},
items: [
{
xtype: 'toolbar',
title: 'Auswahl Ballon',
docked: 'top'
},
{
xtype: 'carousel',
id: 'myCarousel',
flex: 1,
items: [],
config: {
initialize: function() {
console.log('ich initialisiere!');
drawingsStore = Ext.getStore('drawingsStore');
data = drawingsStore.getRange();
console.log('data: ' + data);
for(var i=0;i<data.length;i++){
console.log('ich adde');
this.add({
xtype: 'image',
src: data[i].data.canvasData,
cls: 'card'
});
}
}
},
defaults: {
listeners: {
activate: function(newActive, self, oldActive, opt) {
choosenBalloon = self.getActiveIndex();
console.log(choosenBalloon);
}
}
}
},
{
xtype: 'button',
text: 'OK',
name: 'btnAcceptTemplate',
scope: this,
handler: function() {
this.setBalloonSrc(data[choosenBalloon].data.canvasData);
//this.drawBalloon();
this.initSzeneryCanvas();
panelBalloonSelect.destroy();
}
}
]
});
},
I have an application where i am using sencha touch JS API for UI rendering. The UI works fine in chrome browser but not working in Android or iPhone device.
i have used the following code.
Ext.regModel('Contact', {
fields: ['firstName', 'lastName']
});
var store1 = new Ext.data.JsonStore({
model : 'Contact',
autoLoad : true,
autoDestroy : true,
data: [
{firstName: 'Tommy', lastName: 'Maintz'},
{firstName: 'Rob', lastName: 'Dougan'},
{firstName: 'Ed', lastName: 'Spencer'},
{firstName: 'Abraham', lastName: 'Elias'},
{firstName: 'Jay', lastName: 'Robinson'}
]
});
new Ext.Application({
launch: function() {
var panel = new Ext.Panel({
fullscreen: true,
id:'thePanel',
layout: 'auto',
style: 'background-color:darkblue',
scroll:'vertical'
});
//do this in your dynamically called function
var list = new Ext.List({
id :'theList',
itemTpl : '{firstName} {lastName}',
store: store1,
width: '100%',
scroll:false
});
var stateList = new Ext.form.Select({
label : 'State',
widht: '100%',
options: [
{text: 'First Option', value: 'first'},
{text: 'Second Option', value: 'second'},
{text: 'Third Option', value: 'third'}
],
autoLoad : true,
autoDestroy : true
});
panel.items.add(list);
panel.items.add(stateList);
panel.doLayout();
}
});
It gives the UI like as shown in the image. But the select control is not working for (State list in not populating). please help me.
Each form field needs to have a name property, i.e. the name of the parameter to be send when the form is submitted. Updated your stateList object like this:
var stateList = new Ext.form.Select({
label : 'State',
name: 'selectField',
width: '100%',
options: [
{text: 'First Option', value: 'first'},
{text: 'Second Option', value: 'second'},
{text: 'Third Option', value: 'third'}
],
autoLoad : true,
autoDestroy : true
});