PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.1.1
JetFormBuilder — Dynamic Blocks Form Builder v3.1.1
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 / editor / blocks / controls / fields-map.js
jetformbuilder / assets / src / editor / blocks / controls Last commit date
default-meta.js 2 years ago fields-map.js 2 years ago placeholder.js 2 years ago
fields-map.js
161 lines
1
2 /**
3 * Internal dependencies
4 */
5 const {
6 SelectControl,
7 TextControl
8 } = wp.components;
9
10
11 class JetFieldsMapControl extends wp.element.Component {
12
13 constructor( props ) {
14 super( props );
15
16 this.fieldTypes = this.props.fieldTypes;
17 this.taxonomiesList = this.props.taxonomiesList;
18 this.className = this.props.className;
19 this.metaProp = this.props.metaProp ? this.props.metaProp : 'post_meta';
20 this.termsProp = this.props.termsProp ? this.props.termsProp : 'post_terms';
21 this.index = this.props.index;
22
23 this.init();
24 this.bindFunctions();
25
26 this.state = {
27 type: this.getFieldType( this.props.fieldValue ),
28 };
29 }
30
31 bindFunctions() {
32 this.onChangeType = this.onChangeType.bind( this );
33 this.onChangeValue = this.onChangeValue.bind( this );
34 }
35
36
37 init() {
38 this.id = `inspector-select-control-${ this.index }`;
39 this.preparedTaxes = [];
40 this.taxPrefix = 'jet_tax__';
41
42 if ( ! this.taxonomiesList ) {
43 return;
44 }
45
46 for ( var i = 0; i < this.taxonomiesList.length; i ++ ) {
47 this.preparedTaxes.push( {
48 value: this.taxPrefix + this.taxonomiesList[ i ].value,
49 label: this.taxonomiesList[ i ].label,
50 } );
51 }
52 }
53
54 getFieldName( value ) {
55
56 if ( ! value ) {
57 return '';
58 }
59
60 const fieldType = this.getFieldType( value );
61
62 if ( this.termsProp === fieldType || this.metaProp === fieldType ) {
63 return value;
64 }
65 else {
66 return '';
67 }
68
69 };
70
71 isTermOrMeta( value ) {
72 return ( this.termsProp === value || this.metaProp === value );
73 }
74
75
76 getFieldType( value ) {
77
78 if ( ! value ) {
79 return '';
80 }
81
82 for ( var i = 0; i < this.fieldTypes.length; i ++ ) {
83 if ( value === this.fieldTypes[ i ].value ) {
84 return value;
85 }
86 }
87
88 if ( value.includes( this.taxPrefix ) ) {
89 return this.termsProp;
90 }
91 else {
92 return this.metaProp;
93 }
94
95 };
96
97
98 onChangeValue( newValue ) {
99 this.props.onChange( {
100 ...this.props.fieldsMap,
101 [ this.props.fieldName ]: newValue
102 } );
103 };
104
105
106 onChangeType( newValue ) {
107 let val = this.getFieldType( newValue );
108
109 this.setState( {
110 type: val
111 } );
112
113 if ( this.isTermOrMeta( val ) ) {
114 val = '';
115 }
116
117 this.onChangeValue( val );
118 }
119
120
121 // Disable reason: A select with an onchange throws a warning
122
123 /* eslint-disable jsx-a11y/no-onchange */
124 render() {
125 return <div
126 className="jet-fields-map__row"
127 >
128 <div className="jet-post-field-control">
129 <SelectControl
130 key={ 'field_type_' + this.props.fieldName + this.index }
131 label={ this.props.fieldName }
132 labelPosition="side"
133 value={ this.state.type }
134 onChange={ this.onChangeType }
135 options={ this.fieldTypes }
136 style={ {
137 width: '160px'
138 } }
139 />
140 { ( this.metaProp === this.state.type ) && <TextControl
141 key={ 'field_name_' + this.props.fieldName + this.index }
142 value={ this.props.fieldValue }
143 onChange={ this.onChangeValue }
144 style={ { width: '200px' } }
145 /> }
146 { ( this.termsProp === this.state.type ) && <SelectControl
147 className='jet-control-without-label'
148 key={ 'field_tax_' + this.props.fieldName + this.index }
149 value={ this.props.fieldValue }
150 onChange={ this.onChangeValue }
151 options={ this.preparedTaxes }
152 style={ { width: '200px' } }
153 /> }
154 </div>
155 </div>;
156 }
157
158 /* eslint-enable jsx-a11y/no-onchange */
159 }
160
161 export default JetFieldsMapControl;