Page 1 of 1

Action Buttons

Posted: 26 March 2016, 16:32
by apollo1001
Sorry, another (more serious) problem I am having with action buttons.

I have set up some action buttons, but when they display on the screen they all appear to have the same div id ($12_1). This is then causing issues in the onCubeClick event. Has anyone else experienced anything like this, or can see my silly mistake?

Thanks, Apollo.

Code: Select all

            case 'initialCubeSelection':
                   
                        for ( var id=1; id<=6; id++ ) {
                            var cube = '<div class="cube cube' + id + '" style="display: inline-block;"></div>';
                            var currentChoice = (args.step == 2)? cube + cube : cube;
                            this.addActionButton( 'cubeButton_' + id, _(currentChoice), 'onCubeClick' );
                        }
                    
                   break;

Re: Action Buttons

Posted: 30 March 2016, 08:42
by Quinarbre
Hi,

This code seems fine, maybe you should post the code for onCubeClick in order to see what's going wrong.
onCubeClick should have an argument evt, and then to get the id of your button, you use evt.currentTarget.id

Just a small nitpick about your code : it would probably be cleaner to replace

Code: Select all

var cube = '<div class="cube cube' + id + '" style="display: inline-block;"></div>';
with a suitable this.format_block in order to separate js code from html.

Re: Action Buttons

Posted: 03 April 2016, 17:27
by apollo1001
Thank you for the response. It is basically the same code I used for Keyflower so I was fairly sure there was no problem with it but wanted a second opinion before I suggested it was a bug in the framework...

It looks like the action button id's are not being passed through to the buttons correctly as they are all currently assigned 'id=$12_1' for my project.

Re: Action Buttons

Posted: 25 June 2016, 21:02
by apollo1001
Okay, so I have finally decided to strip this back to nothing and figure out what on earth is causing the problem.

In case anyone else has a similar issue, it seems that {id} is a reserved template block variable name and will overwrite (or mess up) any action button ids. You can fix by simply using {something_id}, {else_id} etc..

I will attempt to add a warning to the studio doc so nobody else wastes months with this bug.