Hello,
I am having a weird issue with character encoding with HTML in a livewire block. It also happens in a normal block. It does not happen if the HTML block is just in a rendered view (i.e. footer).
HTML:
<form
@submit.prevent="doCaptcha"
x-data="{
siteKey: @js(config('services.path.to.google.key')),
init() {
// load our recaptcha.
if (!window.recaptcha) {
const script = document.createElement('script');
script.src = 'https://www.google.com/recaptcha/api.js?render=' + this.siteKey;
document.body.append(script);
}
},
doCaptcha() {
grecaptcha.execute(this.siteKey, {action: 'submit'}).then(token => {
Livewire.dispatch('formSubmitted', {token: token});
});
},
}">
</form>
RENDERED:
<form
@submit.prevent="doCaptcha"
x-data="{
siteKey: 'SITEKEYHERE',
init() {
// load our recaptcha.
if (!window.recaptcha) {
const script = document.createElement('script');
script.src = 'https://www.google.com/recaptcha/api.js?render=' + this.siteKey;
document.body.append(script);
}
},
doCaptcha() {
grecaptcha.execute(this.siteKey, {action: 'submit'}).then(token => {
Livewire.dispatch(‘formSubmitted’, {token: token});
});
},
}”>
</form>
Note the closing quote was encoded to ”
and the line Livewire.dispatch(‘formSubmitted’, {token: token});
.
What is odd is ”
isn’t the encoded version of "
but rather ”
. And ‘
isn’t the encoded version of '
but rather ’
. And more odd is that it is only some characters being encoded. The first line @submit.prevent="doCaptcha"
is left intact and the lines inside the init()
function are fine too.
This doesn’t happen if the HTML block is just in a normal rendered view (footer.blade.php for example). In that case it’s correct. This only happens when it’s in a block or livewire component.
Does anyone have any idea what is going on?
Using:
Sage 11
Bedrock
Acorn