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 / inputs / CheckboxData.js
jetformbuilder / assets / src / frontend / main / inputs Last commit date
ChangeData.js 2 years ago CheckboxData.js 2 years ago InputData.js 2 years ago InputMaskedData.js 2 years ago MultiSelectData.js 2 years ago NoListenData.js 2 years ago RadioData.js 2 years ago RangeData.js 2 years ago RenderStateData.js 2 years ago WysiwygData.js 2 years ago functions.js 2 years ago
CheckboxData.js
90 lines
1 import InputData from './InputData';
2 import ReactiveHook from '../reactive/ReactiveHook';
3 import { getParsedName } from './functions';
4
5 function sanitizeValue( value ) {
6 if ( Array.isArray( value ) ) {
7 return value;
8 }
9
10 return [ value ].filter(
11 Boolean,
12 );
13 }
14
15 /**
16 * @property HTMLCollectionOf<HTMLInputElement> nodes
17 */
18 function CheckboxData() {
19 InputData.call( this );
20
21 this.wrapper = null;
22
23 this.isSupported = function ( node ) {
24 return (
25 node.classList.contains( 'checkradio-wrap' ) &&
26 node.querySelector( '.checkboxes-wrap' )
27 );
28 };
29 this.addListeners = function () {
30 this.enterKey = new ReactiveHook();
31
32 this.wrapper.addEventListener( 'change', () => this.setValue() );
33 this.wrapper.addEventListener(
34 'keydown',
35 this.handleEnterKey.bind( this ),
36 );
37
38 this.wrapper.addEventListener( 'focusout', event => {
39 if ( [ ...this.nodes ].includes( event?.relatedTarget ) ) {
40 return;
41 }
42 this.reportOnBlur();
43 } );
44
45 if ( !this.isArray() ) {
46 return;
47 }
48
49 this.sanitize( sanitizeValue );
50 };
51 this.setValue = function () {
52 this.value.current = this.getActiveValue();
53 };
54
55 this.setNode = function ( node ) {
56 node.jfbSync = this;
57 /**
58 * It should be live collection for the case when items may change
59 */
60 this.nodes = node.getElementsByClassName(
61 'jet-form-builder__field checkboxes-field' );
62
63 this.rawName = this.nodes[ 0 ].name;
64 this.name = getParsedName( this.rawName );
65 this.inputType = 'checkbox';
66
67 /**
68 * @type {HTMLElement|HTMLInputElement}
69 */
70 this.wrapper = node;
71 };
72
73 this.getActiveValue = function () {
74 const value = Array.from( this.nodes ).
75 filter( item => item.checked ).
76 map( item => item.value );
77
78 return this.isArray() ? value : (
79 value?.[ 0 ] ?? ''
80 );
81 };
82
83 this.isArray = function () {
84 return this.nodes.item( 0 )?.name?.includes?.( '[]' );
85 };
86 }
87
88 CheckboxData.prototype = Object.create( InputData.prototype );
89
90 export default CheckboxData;