Skip to content

Commit

Permalink
Merge pull request #412 from Appsilon/esra-update_multiple_checkbox-n…
Browse files Browse the repository at this point in the history
…ot-supporting-choices-with-single-quote

Fix json conversation of strings with single quote
  • Loading branch information
jakubnowicki authored Jan 31, 2024
2 parents 1f3e98d + a2d65e2 commit a07cc1c
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 3 deletions.
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 = "[email protected]", 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
)
))
})

0 comments on commit a07cc1c

Please sign in to comment.