]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
Popover + Tooltip - fix error when content or title is a number
authorJohann-S <johann.servoire@gmail.com>
Fri, 31 Mar 2017 08:03:54 +0000 (10:03 +0200)
committerGitHub <noreply@github.com>
Fri, 31 Mar 2017 08:03:54 +0000 (10:03 +0200)
js/src/tooltip.js
js/tests/unit/popover.js
js/tests/unit/tooltip.js

index 5fd4987b90d90df9f2f208a613ddc3e0faaf41c7..1ff2c4f6e0e9d6f743a87d2b32f5aa54615a87ba 100644 (file)
@@ -605,6 +605,14 @@ const Tooltip = (($) => {
         }
       }
 
+      if (config.title && typeof config.title === 'number') {
+        config.title = config.title.toString()
+      }
+
+      if (config.content && typeof config.content === 'number') {
+        config.content = config.content.toString()
+      }
+
       Util.typeCheckConfig(
         NAME,
         config,
index 64c8c556aca212b4fc0c640502597fd6b5f293d8..eaa9fa0c0d08089dcf5f948dbdf22f51548e7fe1 100644 (file)
@@ -364,4 +364,22 @@ $(function () {
       })
       .modal('show')
   })
+
+  QUnit.test('should convert number to string without error for content and title', function (assert) {
+    assert.expect(2)
+    var done = assert.async()
+    var $popover = $('<a href="#">@mdo</a>')
+      .appendTo('#qunit-fixture')
+      .bootstrapPopover({
+        title: 5,
+        content: 7
+      })
+      .on('shown.bs.popover', function () {
+        assert.strictEqual($('.popover .popover-title').text(), '5')
+        assert.strictEqual($('.popover .popover-content').text(), '7')
+        done()
+      })
+
+    $popover.bootstrapPopover('show')
+  })
 })
index e739f06a50ad0280beb9f8ba332055a911087301..8cb1a6fdf19d2f03a01649b5f505eff0c64ff306 100644 (file)
@@ -886,4 +886,20 @@ $(function () {
 
     $el.bootstrapTooltip('hide')
   })
+
+  QUnit.test('should convert number in title to string', function (assert) {
+    assert.expect(1)
+    var done = assert.async()
+    var $el = $('<a href="#" rel="tooltip" title="7"/>')
+      .appendTo('#qunit-fixture')
+      .bootstrapTooltip('show')
+      .on('shown.bs.tooltip', function () {
+        var tooltip = $el.data('bs.tooltip')
+        var $tooltip = $(tooltip.getTipElement())
+        assert.strictEqual($tooltip.children().text(), '7')
+        done()
+      })
+
+    $el.bootstrapTooltip('show')
+  })
 })