I’m writing a script in javascript to automate some data entry task on a webpage.
the page I’m working on has some text areas that won’t register (would be treated as empty when the page is submitted) as changed unless I declare a change or input event like this:
var evt = new Event("input", {"bubbles":true, "cancelable":false});
element.dispatchEvent (evt);
there’s a datepicker part that accepts manual input or date pick through a calendar thingy.
if I input the date though my code like I’m trying to do, the change again won’t register even with the event dispatch like above.
So, how do I input the date and trigger a change event for that element?
I say that the page is but I could be wrong. some elements have classes that have with ng like "ng-star-inserted"
Thank you
I tried using normal event dispatch but I didn’t work.
2
Answers
I think you might need to simulate user interaction more accurately to trigger the necessary events. One approach you can try is to focus on the element, set its value, and then dispatch a series of events to mimic user behavior
In order to write the value date picker’s control value accessor (CVA) should receive the value through
input
event. Here is how the event is handled in the input. Then in the date picker input event handler checks the value provided here.What you can do is provide the value you need like this:
This way date picker will pass the date to its CVA and the change should be recorded correctly.