A form validation behaviour checks data against a set of criteria before passing it along to the server.
form_validation(
id,
...,
submit_label = "Submit",
submit_class = "",
include_button = TRUE,
inline = FALSE
)
ID of the parent form
A series of field_validation
whose id
are inputs contained within the form
Label to give the submission button at the end of the form (included in returned UI with input
value {id}_submit
)
Additional classes to give the submission button
Logical, should the submit button be included? Defaults to TRUE
. If FALSE
, a
action_button
will be required in the form somewhere with
"submit form-button"
included as part of the class in order for the validation to run.
Logical, do you want the field validation errors as in-line labels (TRUE
),
or in a message box at the bottom of the form (FALSE
)?
A shiny.tag.list
containing the inline JS to perform the form validation in the shiny UI.
If include_button = TRUE
then a button will also be included to appear in the UI.
In order for the validation to work, the form_validation
must be a direct child of the form
.
The "Submit" button has an input value of {id}_submit
and will only trigger
server-side events if all the fields pass validation.
NB If you do not include either form validation input as part of the server-side code then the inputs will pass through to the server as if there were no validation.
if (interactive()) {
library(shiny)
library(shiny.semantic)
library(fomantic.plus)
ui <- semanticPage(
tags$head(
extendShinySemantic()
),
form(
id = "form",
field(
tags$label("Name"),
text_input("name")
),
field(
tags$label("E-Mail"),
text_input("email")
),
form_validation(
id = "form",
field_validation("name", field_rule("empty")),
field_validation("email", field_rule("empty"), field_rule("email"))
)
)
)
server <- function(input, output) {
}
shinyApp(ui, server)
}