PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.1.6
JetFormBuilder — Dynamic Blocks Form Builder v3.1.6
3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.1.0 2.1.1 2.1.10 2.1.11 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 3.0.0 3.0.0.1 3.0.0.2 3.0.0.3 3.0.1 3.0.1.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.0.1 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.3.1 3.3.4 3.3.4.1 3.3.4.2 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.5.1 3.4.5.2 3.4.6 3.4.7 3.4.7.1 3.5.0 3.5.1 3.5.1.1 3.5.1.2 3.5.2 3.5.2.1 3.5.3 3.5.4 3.5.5 3.5.6 3.5.6.1 3.5.6.2 3.5.6.3 3.6.0
jetformbuilder / assets / src / frontend / main / submit / FormSubmit.js
jetformbuilder / assets / src / frontend / main / submit Last commit date
AjaxSubmit.js 2 years ago BaseSubmit.js 2 years ago FormSubmit.js 2 years ago ReloadSubmit.js 2 years ago functions.js 2 years ago
FormSubmit.js
109 lines
1 import LoadingReactiveVar from '../reactive/LoadingReactiveVar';
2 import AjaxSubmit from './AjaxSubmit';
3 import ReloadSubmit from './ReloadSubmit';
4 import { focusOnInvalidInput } from '../functions';
5 import { populateInputs } from '../inputs/functions';
6
7 /**
8 * @param observable {Observable}
9 * @constructor
10 */
11 function FormSubmit( observable ) {
12
13 this.observable = observable;
14 this.lockState = new LoadingReactiveVar( false );
15 this.lockState.make();
16 this.autoFocus = window.JetFormBuilderSettings?.auto_focus;
17
18 /**
19 * @param event {Event}
20 */
21 this.onSubmit = function ( event ) {
22 event.preventDefault();
23
24 this.submit();
25 };
26
27 this.submit = function () {
28 this.observable.inputsAreValid().then( () => {
29 this.clearErrors();
30 this.toggle();
31
32 this.submitter.submit();
33 } ).catch( () => {
34 this.autoFocus && focusOnInvalidInput(
35 populateInputs( this.observable.getInputs() ),
36 );
37 } );
38 };
39
40 this.clearErrors = function () {
41 const messages = this.observable.rootNode.querySelectorAll(
42 '.jet-form-builder-messages-wrap',
43 );
44
45 for ( const message of messages ) {
46 message.remove();
47 }
48 };
49
50 this.toggle = function () {
51 this.lockState.toggle();
52 this.toggleLoading();
53 };
54
55 /**
56 * @private
57 */
58 this.handleButtons = function () {
59 /**
60 * @type {NodeListOf<Element>}
61 */
62 const buttons = this.observable.rootNode.querySelectorAll(
63 '.jet-form-builder__submit',
64 );
65
66 this.lockState.watch( () => {
67 for ( const button of buttons ) {
68 button.disabled = this.lockState.current;
69 }
70 } );
71 };
72
73 this.toggleLoading = function () {
74 this.observable.rootNode.classList.toggle( 'is-loading' );
75 };
76
77 this.createSubmitter = function () {
78 const { classList } = this.observable.rootNode;
79 const isAjax = classList.contains( 'submit-type-ajax' );
80
81 return isAjax ? new AjaxSubmit( this ) : new ReloadSubmit( this );
82 };
83
84 this.getFormId = function () {
85 const { rootNode } = this.observable;
86
87 return +rootNode.dataset.formId;
88 };
89
90 this.onEndSubmit = function ( callable ) {
91 this.submitter.hasOwnProperty( 'status' )
92 ? this.submitter.status.watch( callable )
93 : this.submitter.onFailSubmit( callable );
94 };
95
96 this.observable.rootNode.addEventListener(
97 'submit',
98 ( event ) => this.onSubmit( event ),
99 );
100
101 /**
102 * @type {AjaxSubmit|ReloadSubmit}
103 */
104 this.submitter = this.createSubmitter();
105
106 this.handleButtons();
107 }
108
109 export default FormSubmit;