Files
AVSDevR.HTMLUtils/R/htmlSetXLength.R
Craig Williams 6d3843a92b Package with an initial set of functions added
NOTE: Not all tests have been written yet!
2026-01-22 15:59:54 +00:00

48 lines
1.2 KiB
R

#' Set the maximum length on a text or textarea input
#'
#' @param input The Shiny input to set the length attribute on
#' @param length The maximum length allowed on the input
#'
#' @return The modified input
#' @export
#'
#' @examples
#' x <- shiny::textInput("input_id", "Some text input")
#' htmlSetMaxLength(x, 50)
htmlSetMaxLength <- function(input, length) {
htmltools::tagQuery(input)$
find(".shiny-input-password")$
addAttr(maxlength = length)$
reset()$
find(".shiny-input-text")$
addAttr(maxlength = length)$
reset()$
find("textarea")$
addAttr(maxlength = length)$
allTags()
}
#' Set the minimum length on a text or textarea input
#'
#' @param input The Shiny input to set the length attribute on
#' @param length The minimum length allowed on the input
#'
#' @return The modified input
#' @export
#'
#' @examples
#' x <- shiny::textInput("input_id", "Some text input")
#' htmlSetMinLength(x, 3)
htmlSetMinLength <- function(input, length) {
htmltools::tagQuery(input)$
find(".shiny-input-password")$
addAttr(minlength = length)$
reset()$
find(".shiny-input-text")$
addAttr(minlength = length)$
reset()$
find("textarea")$
addAttr(minlength = length)$
allTags()
}