1
votes

Inside a render function in my template I'm passing this parameter:

placeholderTitle: (gettext "Companie\'s name")

I need to escape the ' because that string is going to be used inside inline javascript:

onfocus="if (this.textContent.trim() == 'Companie's name') {//do someting}"

But like that is not working.

1
"Companie\\'s name"? - Aleksei Matiushkin
@mudasobwa I tried that but it would make one '\' visible in the final string. - Paulo Janeiro

1 Answers

3
votes

You should use Poison.encode! to encode variables that are to be printed in JS code. The following should work if you pass this as an attribute to HTML helpers like content_tag:

onfocus: "if (this.textContent.trim() == #{Poison.encode!(gettext("Companie's name"))} {//do someting}"