Skip to content

Commit 243bdeb

Browse files
authored
form builder meta empty meta key which comes from empty level and duplicate meta key handled (#1271)
1 parent d96d425 commit 243bdeb

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

admin/form-builder/assets/js/form-builder.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,21 @@
122122
state.form_fields[i]['read_only'] = false;
123123
}
124124

125-
if (payload.field_name === 'name' && ! state.form_fields[i].hasOwnProperty('is_new') ) {
125+
let meta_exist = state.form_fields.filter( function (field) {
126+
return 'yes' === field.is_meta && field.name === payload.value;
127+
});
128+
129+
if ( meta_exist.length ) {
130+
swal({
131+
text: 'Duplicate Meta Key',
132+
type: 'warning',
133+
confirmButtonColor: '#d54e21',
134+
confirmButtonText: 'Enter another key',
135+
confirmButtonClass: 'btn btn-success',
136+
});
137+
}
138+
139+
if ( ( payload.field_name === 'name' && payload.value.length - 2 < payload.field_name.length ) || ! state.form_fields[i].hasOwnProperty('is_new') ) {
126140
continue;
127141
} else {
128142
state.form_fields[i][payload.field_name] = payload.value;

assets/js/wpuf-form-builder.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,21 @@
122122
state.form_fields[i]['read_only'] = false;
123123
}
124124

125-
if (payload.field_name === 'name' && ! state.form_fields[i].hasOwnProperty('is_new') ) {
125+
let meta_exist = state.form_fields.filter( function (field) {
126+
return 'yes' === field.is_meta && field.name === payload.value;
127+
});
128+
129+
if ( meta_exist.length ) {
130+
swal({
131+
text: 'Duplicate Meta Key',
132+
type: 'warning',
133+
confirmButtonColor: '#d54e21',
134+
confirmButtonText: 'Enter another key',
135+
confirmButtonClass: 'btn btn-success',
136+
});
137+
}
138+
139+
if ( ( payload.field_name === 'name' && payload.value.length - 2 < payload.field_name.length ) || ! state.form_fields[i].hasOwnProperty('is_new') ) {
126140
continue;
127141
} else {
128142
state.form_fields[i][payload.field_name] = payload.value;

0 commit comments

Comments
 (0)