diff --git a/assets/app.js b/assets/app.js index 0252c349..7b73864d 100644 --- a/assets/app.js +++ b/assets/app.js @@ -7,4 +7,12 @@ import './styles/app.css'; import './scripts/tailmater.js'; import './scripts/datatables.js'; -document.getElementById('snackbar-trigger')?.click(); \ No newline at end of file +import $ from 'jquery'; +global.$ = global.jQuery = $; +import {initFreeFields} from "./scripts/freeField"; + +document.getElementById('snackbar-trigger')?.click(); + +$(document).ready(function() { + initFreeFields(); +}); \ No newline at end of file diff --git a/assets/scripts/freeField.js b/assets/scripts/freeField.js new file mode 100644 index 00000000..e1edb7a5 --- /dev/null +++ b/assets/scripts/freeField.js @@ -0,0 +1,39 @@ +import $ from "jquery"; + +function addFormToCollection($collectionHolderClass) { + var $collectionHolder = $('.' + $collectionHolderClass); + var prototype = $collectionHolder.data('prototype'); + var index = $collectionHolder.data('index'); + var newForm = prototype; + newForm = newForm.replace(/__name__/g, index); + $collectionHolder.data('index', index + 1); + //console.log('index', index); + let $newFormLi = $('
').append(newForm); + $collectionHolder.append($newFormLi); + addTagFormDeleteLink($newFormLi); + $newFormLi.find('input').first().focus(); +} + +function addTagFormDeleteLink($tagFormLi) { + var $removeFormButton = $('