PDA

View Full Version : [FIXED] [PR1] Ext.Carousel.getActiveIndex() returns wrong indexes



SunboX
28 Oct 2011, 1:24 AM
Ext version tested:

Sencha Touch 2.0PR1

Browser versions tested against:

Safari 5.1 (7534.50) on Windows

Description:

I have an Ext.Carousel instance with dynamically added cards. I added 4 different(!) cards. If i listen to the "activeitemchange" event and console.log() the Ext.Carousel.getActiveIndex() value, I get this:


1
0
1
2

That´s wrong! This is what I expected:


0
1
2
3


Test Case:

Ext.setup({
onReady: function() {

var self = this;

var carousel = Ext.create('Ext.Carousel', {
fullscreen: true,

defaults: {
styleHtmlContent: true
},

items: [
{
html : 'Item 1',
style: 'background-color: #5E99CC'
},
{
html : 'Item 2',
style: 'background-color: #759E60'
},
{
html : 'Item 3'
},
{
html : 'Item 4',
style: 'background-color: #759E60'
},
]
});

carousel.on({
activeitemchange: function(carousel){
var activeIndex = carousel.getActiveIndex();

console.log(activeIndex);
}
});

var first = carousel.getInnerItems()[0];
if(first)
carousel.setActiveItem(first);
}
});

HELPFUL INFORMATION

See this URL for live test case:
http://jsfiddle.net/QYJpc/16/ (open with Safari!)

greetings Sunny

SunboX
28 Oct 2011, 1:27 AM
One more, if I slide back and foreward, same cards return different indexes every time.

mitchellsimoens
28 Oct 2011, 6:21 AM
Can you edit your first post so that our bug tracker can correctly parse the thread?

http://www.sencha.com/forum/showthread.php?152646-How-to-report-a-bug

SunboX
28 Oct 2011, 7:09 AM
Thx, done!

greetings Sunny

tfjjones
16 Nov 2011, 11:37 PM
I have just run into this situation but I do not believe it is a bug, more a missing feature.

The documentation for the activeitemchange specifically says

"Note that this event is fired before the value of activeItem (http://10.80.89.170:8000/docs/#!/api/Ext.Container-cfg-activeItem) has been updated, and that you can return false from any listener to the activeitemchange event to cancel the change."

(Important bit: BEFORE the value is updated)

Therefore it is reasonable to assume that the active index has not yet been updated either since it can be cancelled by this event.

So by calling getActiveItem from within the listener you are always getting the previous item's index, not the new one.

Having said that there is currently no way that I can see to get the index of the new activeItem from inside the listener; this is something that should be added I think.

mitchellsimoens
17 Nov 2011, 6:31 AM
We don't have a 'Missing Feature' forum... A missing feature is a subset of a bug

Jacky Nguyen
18 Jan 2012, 4:20 PM
This has been fixed for the next release.

The default order of event listeners is now 'after' instead of 'before', which means all listener callbacks by default will now be invoked after the actions have been taken. Therefore, in the case of 'activeitemchange' event, the listeners will now be called at the end of animation.