Signature-pad on Rails 6 and Webpacker

386 Views Asked by At

Hi I installed with yarn the package [email protected] which I would like to add and use in a Rails 6 project with Webpacker.

However when trying to use the package it throws an error : Uncaught ReferenceError: SignaturePad is not defined

I added in application.js : require("signature_pad")

like other javascript files already added and working as expected.

I am not sure what I am missing.

Thanks in advance for answers and advices.

1

There are 1 best solutions below

0
On

I was able to get it working as well by doing it like this in my application.js file:

import SignaturePad from 'signature_pad/dist/signature_pad.min.js';

var signaturePad = new SignaturePad(document.getElementById('signature-pad'), {
  backgroundColor: 'rgba(255, 255, 255, 0)',
  penColor: 'rgb(0, 0, 0)'
});