Skip to content
This repository was archived by the owner on Sep 28, 2020. It is now read-only.

Define $element.data('bs.tokenfield') earlier. #150

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Haprog
Copy link
Contributor

@Haprog Haprog commented Jul 25, 2014

Define $element.data('bs.tokenfield') at the beginning of Tokenfield() instead of after initialization so the Tokenfield object is also available through $(this).data('bs.tokenfield') in events triggered during initialization. This is useful when tokenfield:createtoken or tokenfield:createdtoken events have been attached before initialization, so they are run on page load if the tokenfield input has a default value on page load.

Before this fix you would get an error if you tried to use $(this).data('bs.tokenfield').$input inside a tokenfield:createtoken event that was bound before tokenfield initialization like this

$('#tokenfield')
    .on('tokenfield:createtoken', function(){
        var $input = $(this).data('bs.tokenfield').$input;
        // Do something with $input
    })
    .tokenfield()

You could just bind the event after .tokenfield() but then the create event would not be run on initialization (on page load) when tokens are created from the default value attribute of the #tokenfield input.

Before this fix you could use a workaround of recreating the tokens after initialization to fire the create events like so $('#tokenfield').tokenfield('setTokens', $('#tokenfield').tokenfield('getTokens')); but this is not needed anymore after this commit.

Define bs.tokenfield at the beginning of Tokenfield() instead of after initialization so the Tokenfield object is also available through $(this).data('bs.tokenfield') in events triggered during initialization. This is useful when createtoken or createdtoken events have been attached before initialization, so they are run on page load if the tokenfield input has a default value on page load.
@Haprog
Copy link
Contributor Author

Haprog commented Jul 25, 2014

This fixes issue #151

@Haprog
Copy link
Contributor Author

Haprog commented Jul 25, 2014

Someone might want to write a test case to ensure that this doesn't break later. I don't yet have experience on writing tests in a JS environment.

@Haprog
Copy link
Contributor Author

Haprog commented Jul 28, 2014

I was also wondering should I run grunt build and include the compiled files in dist/ when submitting a pull request like this? Or do you prefer to build separately?

@Haprog Haprog mentioned this pull request Jul 28, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant