Skip to content

Commit

Permalink
Fixed #126 bug with radio buttons in list elements
Browse files Browse the repository at this point in the history
  • Loading branch information
ausi committed Oct 6, 2020
1 parent 5627d1c commit 1df3516
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/Resources/public/js/be_main.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,19 @@ var persistSelects = function(element) {

}

var preserveRadioButtons = function(element) {
$(element).getElements('input[type=radio]:checked').each(function(input) {
input.setAttribute('data-rsce-checked', '');
});
}

var restoreRadioButtons = function(element) {
$(element).getElements('input[type=radio][data-rsce-checked]').each(function(input) {
input.checked = true;
input.removeAttribute('data-rsce-checked');
});
}

var updateListButtons = function(listElement) {

listElement = $(listElement);
Expand Down Expand Up @@ -236,6 +249,7 @@ var initListSort = function(listInner) {
handle: '.drag-handle',
onStart: function(element) {
removeTinyMCEs(element);
preserveRadioButtons(listInner);
ds.start();
},
onComplete: function() {
Expand All @@ -253,6 +267,7 @@ var initListSort = function(listInner) {
updateListButtons(listInner.getParent('.rsce_list'));
restorePicker(listInner);
restoreChosens(listInner);
restoreRadioButtons(listInner);
}
}));

Expand Down Expand Up @@ -288,6 +303,7 @@ var newElementAtPosition = function(listElement, position) {
removeTinyMCEs(el);
removePicker(el);
});
preserveRadioButtons(listElement);
removeTinyMCEs(dummyItem);
removeACEs(dummyItem);

Expand Down Expand Up @@ -358,6 +374,7 @@ var newElementAtPosition = function(listElement, position) {
restoreTinyMCEs(el);
});
restoreTinyMCEs(newItem);
restoreRadioButtons(listElement);

executeHtmlScripts(newItemHtml);

Expand Down Expand Up @@ -457,6 +474,7 @@ var duplicateElement = function(linkElement) {
removePicker(listInner);
restoreSelectorScripts(element);
persistSelects(element);
preserveRadioButtons(listInner);

var newItem = element.cloneNode(true);

Expand Down Expand Up @@ -492,6 +510,8 @@ var duplicateElement = function(linkElement) {
removePicker(newItem);
restorePicker(listInner);

restoreRadioButtons(listInner);

if (listInner.retrieve('listSort')) {
listInner.retrieve('listSort').addItems(newItem);
}
Expand All @@ -518,6 +538,7 @@ var deleteElement = function(linkElement) {
}

removePicker(listInner);
preserveRadioButtons(listInner);

removeTinyMCEs(element);
if (listInner.retrieve('listSort')) {
Expand All @@ -536,6 +557,7 @@ var deleteElement = function(linkElement) {
});

restorePicker(listInner);
restoreRadioButtons(listInner);

updateListButtons(listElement);

Expand Down Expand Up @@ -573,6 +595,9 @@ var moveElement = function(linkElement, offset) {
removePicker(swapElement);
removePicker(element);

preserveRadioButtons(swapElement);
preserveRadioButtons(element);

element.inject(swapElement, offset > 0 ? 'after' : 'before');

renameElement(swapElement);
Expand All @@ -584,6 +609,9 @@ var moveElement = function(linkElement, offset) {
restorePicker(swapElement);
restorePicker(element);

restoreRadioButtons(swapElement);
restoreRadioButtons(element);

restoreTinyMCEs(swapElement);
restoreTinyMCEs(element);

Expand Down

0 comments on commit 1df3516

Please sign in to comment.