MCPcopy Create free account
hub / github.com/DavidWells/analytics / interceptForm

Function interceptForm

packages/analytics-util-forms/src/onSubmit/handler.js:6–30  ·  view source on GitHub ↗
(opts = {}, element, type)

Source from the content-addressed store, hash-verified

4import { getFormData } from '../utils/getFormValues'
5
6export default function interceptForm(opts = {}, element, type) {
7 const { onSubmit, disableFilter, debug } = opts
8
9 const intercept = function (event) {
10 event.preventDefault()
11 /* Get Raw Form Values */
12 const form = event.target
13 const rawValues = getFormData(form)
14 /* Filter sensitive values */
15 const values = (disableFilter) ? rawValues : filterValues(rawValues, opts, type)
16 if (onSubmit && isFunction(onSubmit)) {
17 onSubmit(event, values, {
18 type: type,
19 form: isForm(element) ? element : null
20 })
21 }
22 if (!debug) {
23 /* Release form */
24 form.removeEventListener(SUBMIT, intercept, false)
25 /* Submit original form */
26 submitForm(form, { timeout: 0 })
27 }
28 }
29 return intercept
30}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected