R/markRequiredInput.R

#' Marks an input field as required
#' appends an asterix to the label und a message unter the label
#' @export
#' @param inputId the id of an input field
#' @param message a messaged showed under the input field label
#' @import shiny
#' @examples
#' \dontrun{
#' markRequiredInput("surename", "field is mandatory")
#' }
markRequiredInput <- function(inputId, message=''){

  jquery <- paste0("label[for='", inputId, "']")

  insertUI(selector=jquery,
           where="beforeEnd",
           ui=tags$span(class="required-asterix","*"))


  insertUI(selector=jquery,
           where="afterEnd",
           ui=tags$p(class="required-error-message",message))

}
mariodejung/samplesubmission documentation built on May 3, 2019, 1:34 p.m.