From b0aa71a302dd351bd81d5f24f0630835dc49626b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Auswo=CC=88ger?= Date: Fri, 8 Dec 2017 14:06:23 +0100 Subject: [PATCH] Persist state of select elements before clonig them, fixes #91 --- src/Resources/public/js/be_main.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/Resources/public/js/be_main.js b/src/Resources/public/js/be_main.js index e77b210..30a50e3 100644 --- a/src/Resources/public/js/be_main.js +++ b/src/Resources/public/js/be_main.js @@ -127,6 +127,25 @@ var restoreSelectorScripts = function(element) { } +var persistSelects = function(element) { + + $(element).getElements('select').each(function(select) { + + var option = select.getElement('option:selected') || select.getElement('option'); + var oldOption = select.getElement('option[selected]'); + + if (oldOption) { + oldOption.removeAttribute('selected'); + } + + if (option) { + option.setAttribute('selected', ''); + } + + }); + +} + var updateListButtons = function(listElement) { listElement = $(listElement); @@ -408,6 +427,7 @@ var duplicateElement = function(linkElement) { removeTinyMCEs(element); restoreSelectorScripts(element); + persistSelects(element); var newItem = element.cloneNode(true);