ebailey78 / shinyBS

Twitter Bootstrap Components for Shiny
182 stars 47 forks source link

Jquery error Uncaught Error: Syntax error, unrecognized expression: # #129

Open selgamal opened 3 years ago

selgamal commented 3 years ago

First, thank you for this package, very useful, secondly, when running shiny app that uses shinyBS I am getting the following error in browser console,

Uncaught Error: Syntax error, unrecognized expression: #
at Function.se.error (jquery.min.js:2)
at se.tokenize (jquery.min.js:2)
at se.select (jquery.min.js:2)
at Function.se [as find] (jquery.min.js:2)
at S.fn.init.find (jquery.min.js:2)
at new S.fn.init (jquery.min.js:2)
at S (jquery.min.js:2)
at exports.InputBinding.initialize (shinyBS.js:49)
at r (init_shiny.js:256)
at initShiny (init_shiny.js:261)

I think the '#' in the line below is causing the error:

https://github.com/ebailey78/shinyBS/blob/c329f8ce43e44579cafbb16fc3109fb69d403e57/inst/www/shinyBS.js#L49

I added the following line to my JS code that runs with the app, and it seems to fix the issue:

shinyBS.inputBindings.modal.initialize = function(el) {
    $($(el).attr("data-sbs-trigger")).attr({"data-toggle": "modal", "data-target": $(el).attr("id")});
  };

I am not a developer, so apologies if this is not a useful comment.

LuShuYangMing commented 3 years ago

Although this could be soloved, bsButton was not worked! @selgamal

srack commented 3 years ago

I've also run across this issue.

shinyBS 0.61 shiny 1.3.2 jquery 3.5.1 (NOTE: does not occur with jquery 1.12.4)

It occurs when the trigger element on the bsModal is not defined, e.g. bsModal("my_modal", "", trigger = "", size = "large", dataTableOutput("my_data_table"))

Documentation on bsModal does not indicate that trigger has to be defined. There are valid use cases for the trigger to not be defined, namely when the modal is opened by code instead of interaction with a DOM element.

With trigger not defined, the start of the line @selgamal refers to in shinyBS.js evaluates to $("#"), which throws an error with 3.5.1.

image

image