I have a panel with a tap listener (red square) and, over it, a button (green). Something like this:
When the button is pressed I want to avoid the tap listener of the red square, but I cant find the way to do this. Could you help me?
This example is not exactly my code (im using controller, dataitems, etc) but is the same problem: http://jsfiddle.net/6ah6U/
Ext.Viewport.add({
xtype: 'panel',
height: 300,
width: 300,
style: 'background: #ff0000',
items: [{
xtype: 'panel',
height: 50,
width: 50,
style: 'background: #00ff00',
listeners: {
tap: function() {
console.log('green tapped');
},
element: 'element'
},
}],
listeners: {
tap: function() {
console.log('red tapped');
},
element: 'element'
},
});
Thanks!
Just stop the propagation of the event in the function handling the tap event on the green panel:
tap: function(btn, e) {
alert('green tapped');
e.stopPropagation();
},
Hope this helps
Firstly, you can give your green square an id:
.......
height: 50,
width: 50,
id: 'green'
.......
Then inside listeners of your red square which is your parent element, you can check the target of your tap event to see whether it's green square or not:
listeners: {
tap: function(e, node) {
if(node.parentNode.id !== 'green') {
console.log('red tapped');
}
},
element: 'element'
}
Notice that I'm using parentNode to follow properly HTML structure of Sencha Touch in this case. You can use inspect element tool to have better understanding about it.
Updated demo: http://jsfiddle.net/6ah6U/1/
Related
I am having a Container. Inside that container I am having 3 companent with draggable: true as below image
I can drag the 3 components within the parent container (move up and down)
But I need to move the 3 component outside the container to left and right side (marked in arrow).
Screenshot of my current screen. I want to move the componets (10, 20, 30) to left side
Can someone please help me on this.
this is the code that I am using
{
xtype: 'container', //Middle Container
width: '100%',
height: '80%',
style: 'background-color: #669900',
layout: 'hbox',
items: [{
xtype: 'component',
itemId: 'markCompxx10',
draggable: true,
width: '100%',
height: '30%',
style: 'background-color: #00EE00',
html: '10',
listeners : { element : 'element', drag : function(e, t) { this.fireEvent('drag', this, e, t); }}
}, {
xtype: 'component',
itemId: 'markCompxx20',
draggable: true,
width: '100%',
height: '30%',
style: 'background-color: #00EE00',
html: '20',
listeners : { element : 'element', drag : function(e, t) { this.fireEvent('drag', this, e, t); }}
}, {
xtype: 'component',
itemId: 'markCompxx30',
width: '100%',
height: '30%',
style: 'background-color: #00FFEE',
html: '30',
listeners : { element : 'element', drag : function(e, t) { this.fireEvent('drag', this, e, t); }}
}]
}
}
thanks
Check out my drag & drop plugin and example. I improved draggable class to support not only components but also elements. That way i could manage to do what you couldnt.
If it doesnt help you, reproduce the same problem in sencha fiddle, so that i can help you.
I am trying to use a navigation view and execute the push and pop operations over it , But cant find where exactly i can define the object view , which would be used for view.push and view.pop.
cause i am getting this error that view isnt defined !
if trying to define Third_Navigate into a var view like
var view = Ext.define('MyFirstApp.view.Third_Naviagte', { .. });
then i am getting the error view.push isnt defined. Help.
Ext.define('MyFirstApp.view.Third_Naviagte', {
extend: 'Ext.navigation.View',
xtype: 'navigationview',
//itemId:'navView',
//we only give it one item by default, which will be the only item in the 'stack' when it loads
config:{
items: [
{
//items can have titles
title: 'Navigation View',
padding: 10,
//inside this first item we are going to add a button
items: [
{
xtype: 'button',
text: 'Push another view!',
handler: function() {
//when someone taps this button, it will push another view into stack
view.push({
//this one also has a title
title: 'Second View',
padding: 10,
//once again, this view has one button
items: [
{
xtype: 'button',
text: 'Pop this view!',
handler: function() {
//and when you press this button, it will pop the current view (this) out of the stack
view.pop();
}
}
]
});
}
}
]
}
]}
});
The reason your example with var view = Ext.define(...); is not working is because Ext.define unlike Ext.create doesn't return an Object instance. It should be var view = Ext.create(...);.
Alternative way to do it would be using the up method used for selecting ancestors.
In your handler function use this to get the button instance and from there you can select the navigationview like so:
handler: function() {
var view = this.up('navigationview');
view.push({
title: 'Second View',
padding: 10,
items: [
{
xtype: 'button',
text: 'Pop this view!',
handler: function() {
view.pop();
}
}
]
});
}
I'm trying to create panel draggable by an element inside that panel.
Unfortunately delegate property is not working in my code and whole panel can be used as drag handle.
What am I doing wrong?
How to fix this code?
I'm using extjs 4.1.1.
Thanks.
http://jsbin.com/ahipob/1/watch
Ext.onReady(function() {
var btn1 = Ext.create('Ext.button.Button', {
text: 'btn1'
});
var btn2 = Ext.create('Ext.button.Button', {
text: 'btn2'
});
var panel1 = Ext.create('Ext.panel.Panel', {
width: 100,
height: 100,
items: [btn1, btn2],
draggable: {
delegate: '#'+Ext.escapeId(btn1.id)
}
});
Ext.create('Ext.Viewport', {
renderTo: Ext.getBody(),
items: [
panel1
]
});
});
I have this code which creates a floating panel centered to the screen:
Ext.define('myapp.view.ButtonNav', {
extend: 'Ext.Container',
xtype: 'myapp_buttonnav',
config: {
fullscreen: false,
layout: 'hbox',
items: [
{
xtype: 'button',
text: 'Button 1',
listeners: {
tap: function () {
var panel = Ext.Viewport.add({
xtype: 'panel',
defaultType: 'button',
baseCls: 'btn1_cont',
centered: true,
layout: {
type: 'vbox',
align: 'center',
pack: 'center'
},
items: [
{
baseCls: 'btn1',
text: 'HOME PAGE',
handler: function() {
Ext.Viewport.setActiveItem({
xtype: 'myapp_homepage'
});
panel.destroy();
}
}
],
top: // SET TOP TO SOURCE BUTTON
left: // SET LEFT TO SOURCE BUTTON
});
}
}
},
]
}
});
As you can see, it is a container, with a button which when clicked shows a floating panel.
How do i position the floating panel centered to the button that triggered the floating panel?
If I understand correctly, you need to use the showBy function like so :
myPanel.showBy(myButton);
It will show the panel next to the button and you can choose the alignment as well.
You can take a look at the documentation
How to get the button
If you take a look at the tap listener signature : http://docs.sencha.com/touch/2-0/#!/api/Ext.Button-event-tap
You can see that the first parameter is the button itself so :
listeners: {
tap: function (myButton, myEvent) {
... // create your panel
myPanel.showBy(myButton);
}
}
Hope this helps
I am trying to use an ActionSheet to present the user several options to continue. I want to add a simple text box in the middle of the screen to describe the problem to the user.
Is there a simple/standard way to put such a prompt in Sencha-Touch?
You'll need to do something like this on your overlay ...
if (!this.popup) {
this.popup = new Ext.Panel({
hideOnMaskTap: false,
floating: true,
modal: true,
centered: true,
hideOnMaskTap: false,
width: 300,
height: 200,
styleHtmlContent: true,
scroll: 'vertical',
html: '<p>msg here</p>'
});
}
this.popup.show('pop');
The key here being hideOnMaskTap: false, this will prevent the overlay from disappearing when you click in it's masked area.
You can then display your action sheet but you must remember to hide the overlay in the handler(s) for your action sheet buttons since it will no longer go away when you tap in the masked area.
if (!this.actions) {
this.actions = new Ext.ActionSheet({
items: [{
text: 'decline',
ui: 'decline',
handler: function() {
this.doWhateverYouNeedToDo();
this.actions.hide();
this.popup.hide();
}
}, {
text: 'save',
handler: function() {
this.doWhateverYouNeedToDo();
this.actions.hide();
this.popup.hide();
}
}, {
text: 'cancel',
scope: this,
handler: function() {
this.doWhateverYouNeedToDo();
this.actions.hide();
this.popup.hide();
}
}]
});
}
this.actions.show();
note the hiding of the overlay in the sheet handlers.. (i don't do it above but you'll more than likely want to destroy the overlay and the action sheet after they are hidden as well just to keep things tidey)
You can use an Overlay popup to display a message after the ActionSheet renders.