The person who started this thread marked my answer as the solution to their specific problem because it worked for them. If it's not working for your issue, I'd suggest starting your own thread detailing your problem. That way you'll get more visability as it'll be the newest post. People will also be able to offer a solution tailored to your specific issue in that instance also.
How to set a value for the date field with JavaScript?
SOLVE
Hey @Pnaumenko, were you able to get it to work? I'm running into the same issue - the date input is actually updated in the DOM, but onSubmit, the field does some kind of refresh and defaults to null (because the date picker interface was not used and therefore points to null).
Inspecting the date picker revelas an HTML table where you could theoretically pinpoint the exact button that corresponds with your date - the button elements for a specific date look something like this:
How to set a value for the date field with JavaScript?
SOLVE
OOO @Pnaumenko Actually I was able to get it working by hiding the field - This was always my plan, but I did not think that it would make a difference. However, because of the idea that the date picker interface was causing the issue, I tried hiding the field and running my original code worked
How to set a value for the date field with JavaScript?
SOLVE
By the way, in case you can't go with the hidden field strategy, I did actually wire up a button click method for logging a virtual click. In the example I mentioned with the button for jan 3rd, 2023, the selector and click would look like this:
The problem is that the event.isTrusted property is set to false for virtual interactions like that, and I couldn't figure out a solution to that. But that selector did work, and the click technically did log.
How to set a value for the date field with JavaScript?
SOLVE
@BarryGrennan Thank you for your response, 'dateVal' was a typo in my example. To be clear, this code runs on a button click and copies a value from the custom date picker to the Form's field. It works okay before submitting the form or focusing on any form field when running HubSpot's validation (in my understanding). After that, it clears the value of the date field, other non-date fields are good