Webpack Encore access module in twig template

68 Views Asked by At

i want to create a DOM related function that i will use in multiple templates of my project. My function works when i write it in a template but when i place it in a dedicated file in my 'assets' folder, it doesn't work anymore.

submitForm.js

function submitForm(buttonId){
  setTimeout(function(){document.getElementById(buttonId).disabled = true;},1000);
  document.getElementById(buttonId).innerHTML = "Chargement";
  }

app.js

// form validation
import './submitForm';

webpack.config.js

const Encore = require('@symfony/webpack-encore');

Encore

    .setOutputPath('public/build/')

    .setPublicPath('/build')

    .addEntry('app', './assets/app.js')

template.twig

{% block script %}

    {{ encore_entry_script_tags('app') }}

<script>
    ....
</script>

{% endblock %}


enter image description here

0

There are 0 best solutions below