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 / package / blocks / hooks / useIsUniqueFieldName.js
jetformbuilder / assets / src / package / blocks / hooks Last commit date
useBlockAttributes.js 2 years ago useFields.js 2 years ago useIsAdvancedValidation.js 2 years ago useIsUniqueFieldName.js 2 years ago useSupport.js 2 years ago useUniqKey.js 2 years ago useUniqueNameOnDuplicate.js 2 years ago
useIsUniqueFieldName.js
81 lines
1 import useRequestFields from '../../actions/hooks/useRequestFields';
2
3 const {
4 useSelect,
5 } = wp.data;
6 const {
7 useBlockEditContext,
8 } = wp.blockEditor;
9
10 const {
11 __,
12 sprintf,
13 } = wp.i18n;
14
15 const actionTypesMap = {};
16
17 for ( const { id, name } of window.jetFormActionTypes ) {
18 actionTypesMap[ id ] = name;
19 }
20
21 function useIsUniqueFieldName() {
22 const { clientId } = useBlockEditContext();
23 const actionFields = useRequestFields(
24 { returnOnEmptyCurrentAction: false },
25 );
26
27 const { inFormFields, hasParent, fieldNames } = useSelect(
28 select => {
29 const currentBlock = select( 'jet-forms/fields' ).
30 getBlockById( clientId );
31
32 return {
33 hasParent: !!currentBlock?.parentBlock,
34 fieldNames: currentBlock?.fields?.map?.(
35 ( { value } ) => value ) ?? [],
36 inFormFields: select( 'jet-forms/fields' ).
37 isUniqueName( clientId ),
38 };
39 },
40 );
41
42 if ( !inFormFields ) {
43 return {
44 error: 'not_unique_in_fields',
45 message: __(
46 'The form field name must be unique. Please change it',
47 'jet-form-builder',
48 ),
49 };
50 }
51
52 if ( hasParent ) {
53 return {};
54 }
55
56 const computed = actionFields.find(
57 ( { value } ) => fieldNames.includes( value ) );
58
59 if ( ! computed ) {
60 return {};
61 }
62
63 return {
64 error: 'not_unique_in_actions',
65 message: computed?.from
66 ? sprintf(
67 __(
68 `The %s action already uses this field name. Please change it`,
69 'jet-form-builder',
70 ),
71 actionTypesMap[ computed.from ],
72 )
73
74 : __(
75 'The form field name must be unique. Please change it',
76 'jet-form-builder',
77 ),
78 };
79 }
80
81 export default useIsUniqueFieldName;