Guidelines
Project Version
No response
Platform and OS Version
No response
Existing Issues
No response
What happened?
When attaching rules on settings, modal function does not check on html::htmlwidgets::JS class.
Consequently, when changing callbacks behavior (like onApprove and onDeny settings), JS code is sent to UI as a string instead of a function.
A solution could be to change :
attach_rule <- function(id, behavior, target, value) {
is_boolean <- (value == "false" || value == "true")
paste0("$(\'#", id, "\').modal(\'", behavior, "\', \'", target, "\', ", if (!is_boolean) "\'", value, if (!is_boolean) "\'", ")")
}
to :
attach_rule <- function(id, behavior, target, value) {
do_not_wrap <- (value == "false" ||
value == "true" ||
"JS_EVAL" %in% class(value))
paste0("$(\'#", id, "\').modal(\'", behavior, "\', \'", target, "\', ", if (!do_not_wrap) "\'", value, if (!do_not_wrap) "\'", ")")
}
Steps to reproduce
- In UI, init a modal like
modal(
id = "my-id",
settings = list(
c("onApprove", htmlwidgets::JS("() => false"))
),
... # modal content,
footer = button(input_id = "my-btn", label = "Do not close modal on click !")
)
- When running, click on
my-btn button should not close modal because JS function return false. However, not only it closes modal, but JS console raises an error due to onApprove being a string instead of a function.
Expected behavior
Code wrapped in html::htmlwidgets::JS should be escaped.
Attachments
No response
Screenshots or Videos
No response
Additional Information
No response
Guidelines
Project Version
No response
Platform and OS Version
No response
Existing Issues
No response
What happened?
When attaching rules on settings,
modalfunction does not check onhtml::htmlwidgets::JSclass.Consequently, when changing callbacks behavior (like
onApproveandonDenysettings), JS code is sent to UI as a string instead of a function.A solution could be to change :
to :
Steps to reproduce
modal( id = "my-id", settings = list( c("onApprove", htmlwidgets::JS("() => false")) ), ... # modal content, footer = button(input_id = "my-btn", label = "Do not close modal on click !") )my-btnbutton should not close modal because JS function return false. However, not only it closes modal, but JS console raises an error due toonApprovebeing a string instead of a function.Expected behavior
Code wrapped in
html::htmlwidgets::JSshould be escaped.Attachments
No response
Screenshots or Videos
No response
Additional Information
No response