How do I initialise a plugin on a component after validation fails?
I have a textarea that line numbers gets added to via JS.
On submit, the textarea is then validated. If validation fails, it renders a normal textarea. I used the element.initialized hook and it worked, but only once - so basically: form is loaded and textarea initialised. It fails validation, and textarea is initialised again. Then it fails validation again, and textarea is the plain, vanilla textarea.
This is the text area:
<textarea class="border-gray-300 block w-full focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50 shadow-sm rounded-none rounded-md" name="results" rows="10" wire:model.defer="unprocessedResults" id="results-textarea"></textarea>
This is my js:
document.addEventListener('livewire:load', function() {
TLN.append_line_numbers('results-textarea');
Livewire.hook('element.initialized', function(el, component) {
TLN.append_line_numbers('results-textarea');
})
});
How do I solve this?