Simplify repetition js

This commit is contained in:
Paul Chavard 2019-02-04 21:04:15 +01:00 committed by simon lehericey
parent a9a853b669
commit cb72507c12

View file

@ -4,21 +4,19 @@ const BUTTON_SELECTOR = '.button.remove-row';
const DESTROY_INPUT_SELECTOR = 'input[type=hidden][name*=_destroy]';
const CHAMP_SELECTOR = '.editable-champ';
addEventListener('turbolinks:load', () => {
delegate('click', BUTTON_SELECTOR, evt => {
evt.preventDefault();
delegate('click', BUTTON_SELECTOR, evt => {
evt.preventDefault();
const row = evt.target.closest('.row');
const row = evt.target.closest('.row');
for (let input of row.querySelectorAll(DESTROY_INPUT_SELECTOR)) {
input.disabled = false;
input.value = true;
}
for (let champ of row.querySelectorAll(CHAMP_SELECTOR)) {
champ.remove();
}
for (let input of row.querySelectorAll(DESTROY_INPUT_SELECTOR)) {
input.disabled = false;
input.value = true;
}
for (let champ of row.querySelectorAll(CHAMP_SELECTOR)) {
champ.remove();
}
evt.target.remove();
row.classList.remove('row');
});
evt.target.remove();
row.classList.remove('row');
});