Skip to content
This repository has been archived by the owner on Oct 9, 2018. It is now read-only.

Set the selected status of an action bar item without invoke the onClick hook defined for the item #770

Closed
xqliu opened this issue Mar 28, 2013 · 3 comments

Comments

@xqliu
Copy link

xqliu commented Mar 28, 2013

Dear All,

I meet an requirement that I would like to set the selected status of an action bar item without invoke the onClick hook defined for the item,

I remember we have a discussion before, for example #598.

Is there any plan to implement this or this there any workaround we could use to implement this?

Regards.
Lawrence.

@xqliu
Copy link
Author

xqliu commented Mar 28, 2013

I am wondering whether we could add the second boolean parameter to indicate whether the onclick need to be invoked. Here are what I have changed in bbui.js, is it possible that we merge this tiny change to current stream to support this?

        actionBar.setSelectedTab = function(tab, invokeOnClick) {
                    if (tab.getAttribute('data-bb-style') != 'tab') return;
                    bb.actionBar.highlightAction(tab);
                    if (tab.onclick && true === invokeOnClick) {
                        tab.onclick();
                    }
                };

@tneil
Copy link
Collaborator

tneil commented Mar 28, 2013

There are a couple of solutions to this.

  1. If you are looking to set the state of the tab before the screen is shown to the user you can set the data-bb-selected="true" attribute in the onscreenready event. This will draw the tab selected but not fire its onclick.

  2. If you need to set the selected state of the tab without the onclick firing after the DOM has been loaded I would suggest the following.

First set your own flag on the tab you want to select and .

var tab = document.getElementById('myTab'),
    actionBar = document.getElementById('myActionBar');

tab.ignoreclick = true;
actionBar.setSelectedTab(tab);

Then in the onclick of your tab check to see if you have set your flag. If you have then return from the event

function myclick() {
   if (this.ignoreclick == true) {
      this.ignoreclick = false;
      return; 
   }

  // My normal onclick function stuff
}

@xqliu
Copy link
Author

xqliu commented Mar 28, 2013

Got it

Very appreciate for your help. 

Sent from Mailbox for iPhone

On Thu, Mar 28, 2013 at 7:27 PM, Tim Neil notifications@github.com
wrote:

There are a couple of solutions to this.

  1. If you are looking to set the state of the tab before the screen is shown to the user you can set the data-bb-selected="true" attribute in the onscreenready event. This will draw the tab selected but not fire its onclick.
  2. If you need to set the selected state of the tab without the onclick firing after the DOM has been loaded I would suggest the following.
    First set your own flag on the tab you want to select and .
var tab = document.getElementById('myTab'),
    actionBar = document.getElementById('myActionBar');
tab.ignoreclick = true;
actionBar.setSelectedTab(tab);

Then in the onclick of your tab check to see if you have set your flag. If you have then return from the event

function myclick() {
   if (this.ignoreclick == true) {
      this.ignoreclick = false;
      return; 
   }
  // My normal onclick function stuff
}

Reply to this email directly or view it on GitHub:
#770 (comment)

@tneil tneil closed this as completed Mar 28, 2013
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants