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

Fix json conversation of strings with single quote #412

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: shiny.semantic
Title: Semantic UI Support for Shiny
Version: 0.5.0.9000
Version: 0.5.0.9001
Authors@R: c(person("Filip", "Stachura", email = "filip@appsilon.com", role = "aut"),
person("Dominik", "Krzeminski", role = "aut"),
person("Krystian", "Igras", role = "aut"),
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

- Fixed `range_input` now returns both lower and upper bound.

- Fixed `update_multiple_checkbox` not supporting choices with single quote.

# [shiny.semantic 0.5.0](https://github.com/Appsilon/shiny.semantic/releases/tag/0.5.0)

- `shiny.semantic` no longer uses CDN as the default source of assets. Instead, `semantic.assets` package was introduced.
Expand Down
4 changes: 2 additions & 2 deletions R/checkbox.R
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,9 @@ multiple_checkbox <- function(input_id, label, choices, choices_value = choices,
update_multiple_checkbox <- function(session = getDefaultReactiveDomain(),
input_id, choices = NULL, choices_value = choices,
selected = NULL, label = NULL) {
if (!is.null(selected)) value <- jsonlite::toJSON(selected) else value <- NULL
if (!is.null(selected)) value <- jsonlite::toJSON(gsub("'", '"', selected)) else value <- NULL
if (!is.null(choices)) {
options <- jsonlite::toJSON(data.frame(name = choices, value = choices_value))
options <- jsonlite::toJSON(data.frame(name = choices, value = gsub("'", '"', choices_value)))
} else {
options <- NULL
}
Expand Down
60 changes: 60 additions & 0 deletions tests/testthat/test_multiple_checkbox.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
context("multiple checkbox")

test_that("test multiple_checkbox input values", {
# type
expect_is(multiple_checkbox(
input_id = "checkboxes",
label = NULL,
choices = ""
),
"shiny.tag")
# empty input
si_str <-
as.character(multiple_checkbox(
input_id = "checkboxes",
label = NULL,
choices = ""
))
expect_true(any(
grepl(
"<div id=\"checkboxes\" class=\"grouped fields ss-checkbox-input\">",
si_str,
fixed = TRUE
)
))
# label
si_str <-
as.character(multiple_checkbox(
input_id = "checkboxes",
label = "My Label",
choices = ""
))
expect_true(any(
grepl("<label for=\"checkboxes\">My Label</label>",
si_str, fixed = TRUE)
))
# selected choices
si_str <-
as.character(
multiple_checkbox(
input_id = "checkboxes",
label = "My Label",
choices = c("A's", "B"),
selected = c("A's", "B")
)
)
expect_true(any(
grepl(
"<input type=\"checkbox\" name=\"checkboxes\" tabindex=\"0\" value=\"A&#39;s\" checked/>",
si_str,
fixed = TRUE
)
))
expect_true(any(
grepl(
"<input type=\"checkbox\" name=\"checkboxes\" tabindex=\"0\" value=\"B\" checked/>",
si_str,
fixed = TRUE
)
))
})
Loading