Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Popover's content function is executed twice #12563

Closed
danieldean44 opened this issue Feb 3, 2014 · 14 comments · Fixed by #14716
Closed

Popover's content function is executed twice #12563

danieldean44 opened this issue Feb 3, 2014 · 14 comments · Fixed by #14716
Milestone

Comments

@danieldean44
Copy link

When using the content function for a popover, it seems to be executed twice when the trigger occurs.

$("#blah").popover({
                    placement: 'bottom',
                    trigger: 'click',
                    content: function () {
                        console.log("Get content");
                        return "Hi";
                    }
                });
@hnrch02
Copy link
Collaborator

hnrch02 commented Feb 3, 2014

This is intentional, AFAICT. Popover.prototype.hasContent checks if the tooltip/popover is empty and based thereon decides if it should be shown in the first place.

@mdo mdo modified the milestones: v3.2.0, v3.1.1 Feb 10, 2014
@zlatanvasovic
Copy link
Contributor

Yes, it checks for emptyness, I don't see any point of this issue.

@cvrebert
Copy link
Collaborator

Possibly we could rework things so that the function is only called once. (It might be an expensive function.)

@zlatanvasovic
Copy link
Contributor

Yes.

2014-02-11 7:50 GMT+01:00 Chris Rebert notifications@github.com:

Possibly we could rework things so that the function is only called once.
(It might be an expensive function.)


Reply to this email directly or view it on GitHubhttps://github.com//issues/12563#issuecomment-34730180
.

Zlatan Vasović - ZDroid

@apaulo
Copy link

apaulo commented Apr 30, 2014

Hi,

If I understand correctly, this will be addressed in Bootstrap v.3.2.0.

In the meantime, is there a turnaround? I am running an AJAX call on content: function() and I'd like to have it run only once...

Of course, I can go via the "show.bs.popover" event, but is there an easier / cleaner way?

(excuse my english, it is a foreign language to me)

@fat
Copy link
Member

fat commented Jun 10, 2014

Yep, the popover function isn't cached. If you want cacheing, you should just do it yourself locally :)

$('[data-toggle="tooltip"]').tooltip({
  title: function () {
    if (this.cache) return this.cache

    // otherwise do a bunch of crazy string
    // manipulation and whatever else

    return this.cache = 'hello'
  }.bind({})
})

@fat fat closed this as completed Jun 10, 2014
@cvrebert
Copy link
Collaborator

I still think that calling the content function twice violates the Principle of Least Surprise.

@cvrebert cvrebert removed this from the v3.2.1 milestone Jun 10, 2014
@danieldean44
Copy link
Author

Yeah - I agree. Why was this closed? Why can't the "check for emptyness" store the content in a variable and reuse it?

@shayneoneill
Copy link

Could this behavior at least be documented in the main instructions. Its fairly bamboozling behavior if its not expected. I'm not sure this really should be a closed issue until its either corrected or documented!

@hnrch02 hnrch02 added docs and removed help wanted labels Sep 23, 2014
@hnrch02 hnrch02 added this to the v3.2.1 milestone Sep 23, 2014
@hnrch02 hnrch02 removed the confirmed label Sep 23, 2014
@hnrch02 hnrch02 reopened this Sep 23, 2014
@hnrch02
Copy link
Collaborator

hnrch02 commented Sep 23, 2014

Reopening since we ought to document this.

@rasmuschristensen
Copy link

A quickfix could be to ensure you have a title in the popover, then this won't happen. Not a beauty, but instead of changing the source.....
When I trigger my popover to load $getJSON I immediatly efter returns a string "loading.....", I would actually have expected this string to show up and fix the issue until the request returned and I could replace the content.....but it don't?

@AdamStelmaszczyk
Copy link

When title or content is empty, the function in content is executed twice. This is VERY surprising. I'm lucky that my friend spotted it, I haven't even noticed it.

My use case was that after the click I was replacing the content. So, the only way to get rid of duplicated, costly AJAX request (which was in the content function) was to set the title and that was my workaround. But, I don't want the title, it looked better without. It's only poor workaround.

It shouldn't work like this that in order to NOT have double request (which is a "feature" that nobody wants) I have to set... a title. It's totally not connected logically, it's bug from my perspective and should be fixed. That callback, no matter what, should be executed only once, like other 99,9%, normal callbacks out there.

@rubystar
Copy link

+1

@cvrebert
Copy link
Collaborator

Locking since this is already on our list for reconsideration in Bootstrap v4.

@twbs twbs locked and limited conversation to collaborators Mar 12, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.