Form in liveview not emitting phx-change

I have a form in a liveview with a few hidden_inputs. Those have their values changed by sliders.
What I am seeing is, that a value change in any form field -not only the hidden ones- by javascript (as opposed to by direct user input) will not cause the pix-change event to fire on the form. Is there any way to make the form emit this event programmatically?

Yes, you need to run the element’s focus method in JavaScript. I can’t find the documentation right now but that should work.

You can also dispatch the event programmatically.

function createEvent(name) {
    const e = document.createEvent("Event");
    e.initEvent(name, true, true);
    return e;
}

inputFieldExample.dispatchEvent(createEvent("input"));
2 Likes

I’ve run into this issue too. Did you manage to find a good solution for this?