Placeholders.js icon indicating copy to clipboard operation
Placeholders.js copied to clipboard

Script not working on dynamically inserted elements

Open crisbeto opened this issue 10 years ago • 4 comments

Elements that are inserted through JavaScript don't get the placeholder functionality. It works when elements are added with jQuery, however it doesn't work on elements added through AngularJS.

Also tried triggering it manually with Placeholders.enable(element); but it doesn't work.

crisbeto avatar Nov 16 '13 21:11 crisbeto

Thanks for reporting this. Can you update the issue with a simple example? That would make it easier for me to debug. I have never noticed any problems with dynamically created elements, but I only actually test ones created with native DOM methods rather than any libraries.

jamesallardice avatar Nov 25 '13 09:11 jamesallardice

After a bit of fiddling with the script I managed to get it to insert the placeholder text when the element is created, however this leaves the possibility of the placeholder text being submitted to the database. In the end I decided to write my own( more angular-friendly) implementation which doesn't interfere with the data bindings. I can post my code if you want. (it involves a dummy element that holds the placeholder and passes the focus to the real one)

crisbeto avatar Nov 25 '13 10:11 crisbeto

Hello crisbeto,

I'd be interested in seeing your solution if you wouldn't mind as I ran into the same problem.

Thanks, Ryan

RyanGladstone avatar Nov 28 '13 17:11 RyanGladstone

Hope it helps: https://gist.github.com/crisbeto/7698305

crisbeto avatar Nov 28 '13 21:11 crisbeto