#' Submit button for validation
#' @export
#' @import shiny
#' @inheritParams shiny::actionButton
#' @param formId ID of form to validate
submit_form <- function(inputId, label, icon = NULL, width = NULL, ..., formId) {
x <- match.call()
x[[1]] <- quote(shiny::actionButton)
shiny::tagList(eval.parent(x),
shiny::tags$script(shiny::HTML(
paste0(
"$(document).on('shiny:inputchanged', function(event) {
if (event.name === '",
inputId,
"' && event.inputType === 'shiny.action' && event.value > 0) {
",if (missing(formId)) {
"var form = $('#' + event.name).closest('form').parsley();"
} else {
paste0("var form = $('#",formId,"').parsley();")
}, "
if (!form.validate()) {
event.preventDefault();
}
}
});"
)
)))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.