Skip to content

Popover's content function is executed twice #12563

Closed

Description

@danieldean44

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";
                    }
                });

Activity

  1. hnrch02 commented on Feb 3, 2014

    @hnrch02
    Collaborator

    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.

  2. modified the milestones: v3.2.0, v3.1.1 on Feb 10, 2014
  3. zlatanvasovic commented on Feb 11, 2014

    @zlatanvasovic

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

  4. cvrebert commented on Feb 11, 2014

    @cvrebert
    Collaborator

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

  5. zlatanvasovic commented on Feb 11, 2014

    @zlatanvasovic

    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

  6. apaulo commented on Apr 30, 2014

    @apaulo

    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)

  7. fat commented on Jun 10, 2014

    @fat
    Member

    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({})
    })
  8. cvrebert commented on Jun 10, 2014

    @cvrebert
    Collaborator

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

  9. removed this from the milestone on Jun 10, 2014
  10. danieldean44 commented on Jun 10, 2014

    @danieldean44
    Author

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

  11. shayneoneill commented on Sep 23, 2014

    @shayneoneill

    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!

  12. 2 remaining items

  13. added this to the milestone on Sep 23, 2014
  14. removed
    confirmedReproduced with a reduced test case
    on Sep 23, 2014
  15. hnrch02 commented on Sep 23, 2014

    @hnrch02
    Collaborator

    Reopening since we ought to document this.

  16. rasmuschristensen commented on Sep 25, 2014

    @rasmuschristensen

    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?

  17. added a commit that references this issue on Oct 2, 2014
    64a74e9
  18. added a commit that references this issue on Oct 9, 2014
    450a616
  19. added a commit that references this issue on Dec 5, 2014
  20. AdamStelmaszczyk commented on Dec 5, 2014

    @AdamStelmaszczyk

    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.

  21. rubystar commented on Mar 12, 2015

    @rubystar

    +1

  22. cvrebert commented on Mar 12, 2015

    @cvrebert
    Collaborator

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

  23. locked and limited conversation to collaborators on Mar 12, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation site and its contentjsJavaScript or TypeScript sources and plugins

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions