painterro icon indicating copy to clipboard operation
painterro copied to clipboard

Multiple show() - Can't get element with id=undefined

Open cavasinf opened this issue 2 years ago • 4 comments

Describe the bug When calling show() function 2 times with a different url the second time, js error is triggered.

Uncaught Error: Can't get element with id=undefined, please create an issue here, we will easily fx it: https://github.com/devforth/painterro/issues/
    getElemByIdSafe painterro.commonjs2.js:1
    getBtnEl painterro.commonjs2.js:1
    setActiveTool painterro.commonjs2.js:1
    placeAt painterro.commonjs2.js:1
    handle painterro.commonjs2.js:1
    <anonymous> painterro.commonjs2.js:1

Painterro version 1.2.73

To Reproduce Steps to reproduce the behavior:

  1. Init Painterro
        this.painterro = Painterro({
            language: 'fr',
            backgroundFillColorAlpha: 0,
            hideByEsc: true,
            colorScheme: {
                main: '#8B817A',
                control: '#1A1A1A',
                controlContent: '#fff',
                controlShadow: 'none',
                activeControl: '#6F6762',
                activeControlContent: '#fff',
                hoverControl: '#6F6762',
                hoverControlContent: '#fff',
            },
            defaultTool : 'brush',
            hiddenTools: [
                'select',
                'crop',
                'pixelize',
                'line',
                'arrow',
                'rect',
                'ellipse',
                // 'brush',
                // 'eraser',
                'text',
                'rotate',
                'resize',
                // 'save',
                'open',
                // 'close',
                // 'undo',
                'redo',
                // 'zoomin',
                // 'zoomout',
                'bucket',
                'clear',
                'settings',
            ],
            saveHandler: this._onPainterroSave,
        });
  1. Have multiple button to trigger painterro.show(url) with different urls
        this.selectPlanTargets.forEach(planTarget => {
            planTarget.addEventListener('click', (event) => {
                this.painterro.show(event.target.dataset.url);
            });
        });
  1. Open painterro Once with url
  2. Close painterro modal
  3. Open painterro with another url
  4. Click on extend, or other
  5. See error

Expected behavior No JS Error, and be able to open different url from the same painterro instance.

Screenshots

Step 2

image

Step 3

image

Step 6

image

Step 7

image

Browser FireFox 99.0.1 (64 bits) on Windows

cavasinf avatar May 03 '22 08:05 cavasinf

Added a potential fix, however when select is non default tool I found some ieeus with placing and second show does placing. If you are still working on this please check it out, if some other issues will be there please let me know

ivictbor avatar May 05 '22 21:05 ivictbor

BTW You might want to pay attention on this text from Readme:

how_to_paste_actions: If there is only one option in list, then it will chosen automatically without dialog

ivictbor avatar May 06 '22 07:05 ivictbor

Quick fix ! I'll try that next week, thanks!


however when select is non default tool I found some ieeus

Never though the problem was coming from that.


how_to_paste_actions: If there is only one option in list [...]

But if you want to:

  • Handle CTRL + V from the user and allowing him to do what he want (replace, paste on it, extend..).
  • Open a new url with show() that replaces all the content.

When this option has only one choice, there will be a conflict with what I want to allow VS what I'll get, No ?

cavasinf avatar May 06 '22 07:05 cavasinf

Never though the problem was coming from that.

Me too 😀 It feels like the amount of options that painterro now has creates a lot of different corner cases =)

there will be a conflict with what I want

Yep, currently all options that might add image would it be

  • pasting image from clipboard
  • Opening it from painterro Open button
  • show() on non-empty painterro instance All runs same code which respects how_to_paste_options

If you need always to replace content when you call show you can easily workaround it by

p.clear()
p.show(<new url>)

ivictbor avatar May 06 '22 08:05 ivictbor