painterro
painterro copied to clipboard
Multiple show() - Can't get element with id=undefined
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:
- 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,
});
- 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);
});
});
- Open painterro Once with url
- Close painterro modal
- Open painterro with another url
- Click on extend, or other
- See error
Expected behavior No JS Error, and be able to open different url from the same painterro instance.
Screenshots
Step 2
Step 3
Step 6
Step 7
Browser FireFox 99.0.1 (64 bits) on Windows
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
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
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 ?
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>)