Skip to content

Commit 9ddacd0

Browse files
fix: clone field conditions
1 parent 201841d commit 9ddacd0

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

js/admin/ppom-admin.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,6 @@ jQuery(function($) {
595595
// handle multiple options
596596
var ppom_option_type = 'ppom_copy_option';
597597
var option_selector = clone_new_field.find('.ppom-option-keys');
598-
var add_cond_selector = clone_new_field.find('.ppom-conditional-keys');
599598
var eventcalendar_selector = clone_new_field.find('.ppom-eventcalendar-field');
600599
var image_option_selector = clone_new_field.find('[data-table-id="image"] .data-options, [data-table-id="imageselect"] .data-options');
601600

@@ -604,7 +603,6 @@ jQuery(function($) {
604603
clone_new_field.find('[data-table-id="audio"] .pre-upload-box li').remove();
605604
// clone_new_field.find('[data-table-id="imageselect"] .pre-upload-box li').remove();
606605
// clone_new_field.find('.data-options').not(':last').remove();
607-
clone_new_field.find('.webcontact-rules').not(':last').remove();
608606

609607
// set existing conditions meta
610608
$(clone_new_field).find('select[data-metatype="elements"]').each(function(i, condition_element) {
@@ -631,7 +629,10 @@ jQuery(function($) {
631629
var option_controller = clone_new_field.find('.ppom-fields-option');
632630

633631
ppom_option_controller(option_controller, field_index, option_index, ppom_option_type);
634-
ppom_add_condition_set_index(add_cond_selector, field_index, field_type, option_index);
632+
clone_new_field.find('.webcontact-rules').each(function(index, rule_row) {
633+
const rule_inputs = $(rule_row).find('.ppom-conditional-keys');
634+
ppom_add_condition_set_index(rule_inputs, field_index, field_type, index);
635+
});
635636

636637
// for eventcalendar changing index
637638
ppom_eventcalendar_set_index(eventcalendar_selector, field_index);
@@ -961,6 +962,10 @@ jQuery(function($) {
961962
}
962963

963964
}).on('click', '.ppom-remove-rule', function(e) {
965+
const div = $(this).parents('.form-group');
966+
const option_index = parseInt(div.find('.ppom-condition-last-id').val());
967+
div.find('.ppom-condition-last-id').val(option_index - 1);
968+
964969
var removeButton = $(this );
965970
if (removeButton.parents('.ppom-condition-clone-js')?.find('.webcontact-rules')?.length === 1) {
966971
removeButton

0 commit comments

Comments
 (0)