Set or clear a field's error state from the server
Source:R/form-message.R
update_shad_form_field.RdPushes a shadcn error message into the shad_form_field() wrapping a control,
toggling data-invalid, aria-invalid, and aria-describedby and
creating/removing the message element. This is the primitive that
shad_validator() and shinyvalidate bridges build on.
Usage
update_shad_form_field(
inputId,
error = NULL,
session = shiny::getDefaultReactiveDomain()
)See also
Other shadshiny forms:
shad_field_group(),
shad_field_separator(),
shad_fieldset(),
shad_form_counter(),
shad_form_message(),
shad_form_summary(),
shad_rules,
shad_validator()
Examples
if (interactive()) {
ui <- page_shad(
shad_form_field(shad_input("email"), label = "Email", inputId = "email"),
shad_button("Check", inputId = "check")
)
server <- function(input, output, session) {
shiny::observeEvent(input$check, {
ok <- grepl("@", input$email, fixed = TRUE)
update_shad_form_field("email", if (!ok) "Enter a valid email address.")
})
}
shiny::shinyApp(ui, server)
}