form_validation {fomantic.plus}R Documentation

Form Validation for Fomantic UI

Description

A form validation behaviour checks data against a set of criteria before passing it along to the server.

Usage

form_validation(
  id,
  ...,
  submit_label = "Submit",
  submit_class = "",
  include_button = TRUE,
  inline = FALSE
)

Arguments

id

ID of the parent form

...

A series of field_validation whose id are inputs contained within the form

submit_label

Label to give the submission button at the end of the form (included in returned UI with input value {id}_submit)

submit_class

Additional classes to give the submission button

include_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.

inline

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)?

Details

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.

Value

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.

References

https://fomantic-ui.com/behaviors/form.html

See Also

field_validation, form_button

Examples

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)
}


[Package fomantic.plus version 0.1.0 Index]