Package with an initial set of functions added
NOTE: Not all tests have been written yet!
This commit is contained in:
35
R/htmlMarkOptional.R
Normal file
35
R/htmlMarkOptional.R
Normal file
@@ -0,0 +1,35 @@
|
||||
#' Explicitly mark a Shiny input as optional
|
||||
#'
|
||||
#' @param input The Shiny input to mark as optional
|
||||
#' @param optClass The classes to add to the indicator text
|
||||
#'
|
||||
#' @return The modified input
|
||||
#' @export
|
||||
#'
|
||||
#' @examples
|
||||
#' x <- shiny::textInput("input_id", "Some text input")
|
||||
#' htmlMarkOptional(x)
|
||||
htmlMarkOptional <- function(input, optClass = "text-muted font-italic") {
|
||||
opt_span <- htmltools::tags$span(class = optClass, " (optional)")
|
||||
tq <- htmltools::tagQuery(input)
|
||||
if (tq$hasClass("shiny-input-checkboxgroup")) {
|
||||
tq <- tq$
|
||||
children("label")$append(opt_span)$
|
||||
reset()
|
||||
} else if (tq$find(".shiny-options-group")$length() > 0) {
|
||||
tq <- tq$
|
||||
children("label")$append(opt_span)$
|
||||
reset()
|
||||
} else if (tq$find(".btn-file")$length() > 0) {
|
||||
tq <- tq$
|
||||
children("label")$append(opt_span)$
|
||||
reset()
|
||||
} else {
|
||||
tq <- tq$
|
||||
children(".checkbox")$find("label span")$append(opt_span)$
|
||||
reset()$
|
||||
find("label.control-label")$append(opt_span)$
|
||||
reset()
|
||||
}
|
||||
tq$allTags()
|
||||
}
|
||||
Reference in New Issue
Block a user