Skip to content

Commit

Permalink
Made tiny CS fixes on app.js and draggable.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierstoval committed Feb 12, 2020
1 parent f61b719 commit 9ca00fd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion assets/js/app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import '../css/app.css';
import * as Highcharts from "highcharts";
import {draggable} from './draggable';
import './draggable';

global.Highcharts = Highcharts;
24 changes: 13 additions & 11 deletions assets/js/draggable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@ const sortable = new Sortable(document.querySelectorAll('.draggable_container'),
draggable: '.draggable'
});

sortable.on('sortable:stop', (event) => {
const draggedInputs = document.querySelectorAll('.draggable_container .draggable input');
draggedInputs.forEach((input: Element, index: number) => {
if (input.hasAttribute('name')) {
let name = input.getAttribute('name') || '';
if (!name.match(/\[\d+]/)) {
// No DOM modification if attribute was removed already.
return;
sortable.on('sortable:stop', () => {
document
.querySelectorAll('.draggable_container .draggable input')
.forEach((input: Element, index: number) => {
if (input.hasAttribute('name')) {
let name = input.getAttribute('name') || '';
if (!name.match(/\[\d+]/)) {
// No DOM modification if attribute was already removed.
return;
}
input.setAttribute('name', name.replace(/\[\d+]/g, '['+index+']'));
}
input.setAttribute('name', name.replace(/\[\d+]/g, '['+index+']'));
}
});
})
;
});

0 comments on commit 9ca00fd

Please sign in to comment.