sencha touch 2: card layout within one of the panel of a carousel - sencha-touch

What I'm trying to do here is to use a card layout within the panel of a carousel. But it seems impossible that it's not common to create a card layout and the carousel is actually one of the card-layout-like container. So I wonder if it can be achieved in Sencha Touch 2.
Here is my main view, a plain carousel container:
Ext.define("myapp.view.Main", {
extend: 'Ext.carousel.Carousel',
config: {
defaults: {
styleHtmlContent : true
},
activeItem: 0,
items: [
{
xtype: 'firstview'
},
{
xtype: 'secondview'
},
{
xtype: 'thirdview'
}
]
}
});
and here is my 'firstview', which extends the Ext.Panel as part of the carousel container:
Ext.define("myapp.view.Compose", {
extend: 'Ext.Panel',
xtype: 'firstview',
requires: [
'Ext.form.FieldSet',
'Ext.TitleBar',
'Ext.form.Text',
'Ext.Button'
],
config: {
styleHtmlContent: true,
scrollable: true,
layout: 'vbox',
items: [
{ // title bar
xtype: 'titlebar',
docked: 'top',
title: 'a Title here'
},
{
xtype: 'toolbar',
docked: 'top',
layout: {
type: 'vbox',
align: 'center',
pack: 'center'
},
items: [
{ // controll button set - to change view for composing different kinds of messages
xtype: 'segmentedbutton',
allowDepress: true,
allowMultiple: false,
items: [
{
text: 'subview-1',
pressed: true
},
{
text: 'subview-2'
},
{
text: 'subview-3'
}
]
}
]
},
{
xtype: 'container',
id: 'id_compose_card',
layout: {
type: 'card',
align: 'center',
pack: 'top'
},
config: {
height: '100%',
items: [
{
html: 'card 1'
},
{
html: 'card 2'
}
]
}
}
]
}
});
as you can see, there is a card layout within this panel. But as a matter of fact nothing is not going to display.
Of course, I can find another way out to achieve some thing similar here, but I just want to know is it impossible to embed a card container into a card-layout-like container, for example, 'tabPanel' or 'carousel' in sencha touch 2?

Hey in the Compose widget replace the the part with id:'id_compose_card'
with this
{
xtype: 'container',
id: 'id_compose_card',
layout: {
type: 'card',
align: 'center',
pack: 'top'
},
flex: 1,
items: [
{
html: 'card 1'
},
{
html: 'card 2'
}
]
}
I just took out the parts inside the config object and put them outside. Im getting this feeling that u cant nest a config inside another config object for a class definition. A lot of people are having issue and this seems to be the problem. You might want to confirm this on their forum.
Then I also replaced the attribute
height: '100%',
with this
flex:1
This will tell the vbox layout to make your component fill the remaining space.

Related

How to place a button inside an input field using Sencha Touch?

When I try to put a container as a component in the textfield (according to Button inside of an input field Sencha Touch 2.0) my app crashes. The code below is for you to get an idea of the context, im didnt double check the syntax in the post but when I comment out the last item it works fine . I think it is the xtype: 'container' that generates the error (the error is "undefined function"). What am I doing wrong here? Im so bad at this...
Ext.define('myapp.view.AddAdvertView', {
extend: 'Ext.form.Panel',
xtype: 'addadvertview',
requires: [
'Ext.form.FieldSet',
'Ext.field.Text',
'Ext.field.Number',
'Ext.Button',
'Ext.field.Toggle',
'Ext.Container'
],
config: {
title: 'AddAdvertView',
items: [
{
name: 'heading',
xtype: 'textfield',
label: 'Heading',
border: 10,
margin:'0 0 1 0',
},
{
xtype: 'textfield',
component: {
xtype: 'container',
layout: 'hbox',
items: [
{
xtype: 'textfield',
flex: 3,
},
{
xtype: 'button',
flex: 1,
text: 'test'
}
]
},
})
You are right. The problem is the container inside the textfield.
When a textfield is generated and initialized it will set its original value. Since you have changed the component to container and it's not input anymore you get the problem. The initialization process calls the getValue methode of the component. Unfortunately container does not have one and that's rises the exception.
The solution to this problem is quite easy: create your custom textfield and override its getValue method.
Ext.define("MyApp.field.ButtonField", {
extend: "Ext.field.Text",
xtype: "buttonfield",
config: {
label: 'Textfield',
component: {
xtype: 'container',
layout: 'hbox',
items: [
{
xtype: 'textfield',
flex: 3,
},
{
xtype: 'button',
flex: 1,
text: 'test'
}
]
}
},
getValue: function () {
this.getComponent().down('textfield').getValue();
},
setLabel: function ( label ) {
this.getComponent().down('textfield').setLabel( label );
}
});
Since it has an xtype you can use it as follows:
Ext.define('MyApp.view.AddAdvertView', {
extend: 'Ext.form.Panel',
xtype: 'addadvertview',
requires: [
'Ext.form.FieldSet',
'Ext.field.Text',
'Ext.field.Number',
'Ext.Button',
'Ext.field.Toggle',
'Ext.Container',
'MyApp.field.ButtonField'
],
config: {
title: 'AddAdvertView',
items: [
{
name: 'heading',
xtype: 'textfield',
label: 'Heading',
border: 10,
margin:'0 0 1 0',
},
{
xtype: 'buttonfield',
label: 'blub'
}
]
}
});
You have to override some more methods (e.g. setValue) if you want to use the buttonfield like a normal field. So you delegate all textfield method calls to the wrapped textfield. But that should be easy now.

How to select a container in Sencha Touch 2.3.1

I'm trying to display a "list" of containers: I mean I created a container ( I'll call it container A ) to display data:
ID docked on the left of the container, name on top, task name ( for example ) at bottom and date docked on the right.
Next I try to display this containers in another container ( container B): some containers inside a bigger container so I can display the data.
But I need to select a container A if I want to delete or edit it. How can I do it?
Thank you very much.
Edit:
Code: "container A" (.../app/view/Cliente.js)
Ext.define('proyecto.view.Cliente', {
extend: 'Ext.Container',
xtype: 'cliente',
requires: ['Ext.TitleBar'],
config: {
title: 'Cliente',
iconCls: 'info',
xtype: 'container',
layout: 'vbox',
margin: 10,
padding: 5, border: 15,
items: [
{
docked: 'left',
xtype: 'container',
width: 100,
html: 'ID_cliente',
style: 'background-color: #00CED1'
},
{
xtype: 'container',
flex: 2,
html: 'Nombre',
style: 'background-color: #6495ED'
},
{
xtype: 'container',
flex: 1,
html: '<DIV ALIGN=right><span style="background-color:#4169E1">Asignaciones</span></DIV>',
},
]
}});
Code: "container B" (.../app/view/ListaClientes.js)
Ext.define('proyecto.view.ListaClientes', {
extend: 'Ext.Container',
xtype: 'listaclientes',
requires: ['Ext.TitleBar', 'proyecto.view.Cliente'],
config: {
title: 'Lista de Clientes',
iconCls: 'team',
scrollable: true,
items: [
{
xtype: 'toolbar',
title: 'Lista de clientes',
docked: 'top',
items: [
{
text: 'Nuevo'/*,
action: 'nuevocliente'*/
},
{
text: 'Editar'/*,
action: 'editarcliente',
enableOnSelection: true,
disabled: true */
},
{
xtype: 'spacer'
},
{
text: 'Eliminar'/*,
action: 'eliminarcliente',
enableOnSelection: true,
disabled: true */
}
]
},
{ //example visualization
xtype: 'cliente',
height: 80,
},
{
xtype: 'cliente',
height: 80,
},
{
xtype: 'cliente',
height: 80,
},
{
xtype: 'cliente',
height: 80,
}
]
}});
Screen Container B: I can't upload the screen here, I'm newbie :(
http://s7.postimg.org/q0gppq8h7/Container_B.jpg
I would assume the container you mentioned is not a generic container in HTML form concept but a real class in sencha touch.
I would recommend you to have a look how to use the component query in sencha touch framework, as that is the most powerful and basic search utility in the framework. if you organise your object properly, it can get anything for you easily. if you from css & jquery selector background, you feel you were home when checking how to use
have a look here:
http://docs.sencha.com/touch/2.3.1/#!/api/Ext.ComponentQuery
if you also interested with the jquery type of search which is at the dom level, here is a good example.
http://docs.sencha.com/core/manual/content/element.html
also, some similar feature offered in:
docs.sencha.com/touch/2.3.1/#!/api/Ext-method-getCmp
I use the 2.3 as an example, but these features exist since earlier release. Hopefully these can help.

Sencha touch button component setText() is not changing button text

I have a controller function for my list that is being called when the list item is tapped, within this function I am trying to update a button component's text as follows:
var button = this.getPopupButton();
//reference popupButton is set within controller
button.setText('Test');
The function seems to work, and console.info(button.getText()); is reporting the update, but within the UI the text remains the default as set in the config.
Is this a bug? Or am I doing something wrong here?
These buttons are within a segmented button object:
items: [
{
xtype: 'segmentedbutton',
flex: 1,
allowDepress: true,
layout: {
align: 'stretchmax',
pack: 'center',
type: 'hbox'
},
items: [
{
xtype: 'button',
flex: 2,
id: 'PopUpButton',
text: 'Pop up test!'
},
{
xtype: 'button',
flex: 1,
id: 'Mini',
ui: 'action',
text: 'Mini test!'
}
]
}
]
Update: It might help to know that these buttons are segmented buttons within a datalist toolbar, see complete code below:
Ext.define('TestApp.view.ItemList', {
extend: 'Ext.dataview.List',
alias: 'widget.ItemList',
config: {
loadingText: 'Loading items...',
store: 'ItemStore',
cls: [
'ItemList'
],
itemTpl: Ext.create('Ext.XTemplate',
'<div>{itemData}</div>',
),
plugins: [
{
xtype: 'component',
refreshFn: function(plugin) {
//console.info('pull to refresh!');
var store = plugin.up().getStore();
console.log(store);
},
itemId: 'PullToRefresh',
loadingText: 'Loading...',
pullRefreshText: 'Pull down to refresh...',
releaseRefreshText: 'Release to refresh...',
snappingAnimationDuration: 200,
type: 'pullrefresh'
},
{
autoPaging: true,
loadMoreText: 'Load more...',
noMoreRecordsText: 'No more data in feed',
type: 'listpaging'
}
],
items: [
{
xtype: 'toolbar',
docked: 'top',
id: 'MediaToolbar',
ui: 'light',
zIndex: 3,
items: [
{
xtype: 'button',
flex: 1,
cls: 'SourceSelectButton',
id: 'SourceSelectButton',
minWidth: '',
width: 83,
iconCls: 'ItemSource1',
text: ''
}
]
},
{
xtype: 'toolbar',
docked: 'top',
height: '45px',
id: 'FeedSelectorBar',
ui: 'light',
zIndex: 3,
items: [
{
xtype: 'segmentedbutton',
flex: 1,
id: 'FeedSelectorButtons',
allowDepress: true,
layout: {
align: 'stretchmax',
pack: 'center',
type: 'hbox'
},
items: [
{
xtype: 'button',
flex: 2,
id: 'PopUpButton',
text: 'Pop up test'
},
{
xtype: 'button',
flex: 1,
id: 'TesterButton',
ui: 'action',
text: 'Latest'
}
]
}
]
}
]
}
});
Update #2: After further testing in the console using Ext.ComponentQuery.query() I have found that I can manipulate all buttons in my application EXCLUDING the ones placed within the dataview list/toolbar.
Try following changes, this is working for me:-
Give 'id' to your segmented button.
{
xtype: 'segmentedbutton',
id: 'hii', // give id to your segmented button
allowDepress: true,
layout: {
align: 'stretchmax',
pack: 'center',
type: 'hbox'
},
items: [
{
xtype: 'button',
id: 'PopUpButton',
text: 'Pop up test!'
},
{
xtype: 'button',
id: 'Mini',
ui: 'action',
text: 'Mini test!'
}
]
}
Use this code inside controller on 'itemtap' of your list.
var button = Ext.getCmp('hii'); // use your segmented button id here
button.getAt(1).setText('Test');
This problem was solved by moving my Ext.dataview.List into a Ext.panel container. This seems to be a bug with sencha touch 2.0.1.1. Any elements that I manipulated within my dataview.List toolbar component would report as updated in the console but would not show as updated in the UI. The same problem occured in both Chrome, Safari and on an Android device packaged as a phonegap project.

Referencing the HTML objects inside a Sencha Touch Container

I'm using Sencha Touch 2.0.1. I'm trying to get a reference to some HTML in a Container. (My objective is to read the width of the object, and shrink the font size if necessary so it fits nicely).
Here's my code:
Ext.define("SFCT.view.Flashcard", {
extend: 'Ext.Container',
xtype: 'flashcardpanel',
requires: [
'Ext.TitleBar'
],
config: {
itemId: 'mainScreen',
title: 'Flashcards',
layout: 'fit',
items: [
{
xtype: 'container',
layout: {
type: 'vbox',
pack: 'center'
},
items: [
{
xtype: 'container',
itemId: 'wordContainer'
}
],
style: 'text-align: center'
},
{
xtype: 'button',
docked: 'right',
text: 'Next',
action: 'next'
}
]
},
updateWord: function(newWord) {
var s = '<div style="font-size: 72px">' + newWord+ '</div>';
var c = Ext.ComponentQuery.query('#wordContainer')[0];
console.log(c.getHtml());
c.setHtml(s);
}
});
If I use Ext.Container.getHtml() as shown above, it returns the HTML as a string. But I'm looking for a reference to the div element itself, so that I can get its width.
Any ideas how I can do that?
Thanks.
If I'm not mistaken
c.element
Should get you a reference to the wrapped element.

Prevent Carousel scroll within scrollable Container (Sencha 2)?

I've got a Container with a header, content (Carousel) and a footer. The Container itself is therefor scrollable (vertical) to be able to scroll down to the footer. The Carousel can be swiped horizontally to change active item. I want to lock it to do only two thing:
If starting to move vertically, only scroll Container
If starting to move horizontally, only scroll Carousel
If you now grab the Carousel you are able to scroll both ways at the same time. Example code:
Ext.define('MyApp.view.MyContainer', {
extend: 'Ext.Container',
config: {
scrollable: true,
items: [
{
xtype: 'container',
items: [
{
xtype: 'label',
html: 'abc'
}
]
},
{
xtype: 'carousel',
height: 200,
scrollable: false,
items: [
{
xtype: 'label',
html: 'x'
},
{
xtype: 'label',
html: 'y<br/>y<br/>y<br/>y<br/>y<br/>y<br/>y<br/>y'
}
]
},
{
xtype: 'container',
items: [
{
xtype: 'label',
html: 'def'
}
]
}
]
}
});
Using Sencha Touch 2.
You might need to block the over scrolling .This will help to prevent both vertical scrolling and carousel item change happening at the same time.Try this code inside your scrollable of container.
scrollable: {
directionLock: true,
direction: 'vertical',
momentumEasing: {
momentum: {
acceleration: 30,
friction: 0.5
},
bounce: {
acceleration: 0.0001,
springTension: 0.9999,
},
minVelocity: 3
},
outOfBoundRestrictFactor: 0
},
If starting to move horizontally, only scroll Carousel
Just add this to the config of your container :
config: {
scrollable: {
direction: 'vertical',
directionLock:true
}
}
I still haven't figured out how to lock the carousel when you scroll vertically. I'll let you know if I find out.
Try this one.It is working fine for me.
Ext.define('MyApp.view.MyContainer', {
extend: 'Ext.Container',
config: {
scrollable: {
direction: 'vertical'
},
items: [
{
xtype: 'container',
items: [
{
xtype: 'label',
html: 'abc'
}
]
},
{
xtype: 'carousel',
height: 200,
direction: 'horizontal',
directionLock: true,
items: [
{
xtype: 'label',
html: 'x'
},
{
xtype: 'label',
html: 'y<br/>y<br/>y<br/>y<br/>y<br/>y<br/>y<br/>y'
}
]
},
{
xtype: 'container',
items: [
{
xtype: 'label',
html: 'def'
}
]
}
]
}
});