WixFormv2 - New Forms Issue with Event onClick

I have created a wix form (New form). Based on input value on the form, before submit I want to assign it to another field (finalAnswer ) but wixformv2 doesn’t call onSubmit event when I click the Submit button. Can someone please help

$w(“#form1”).onSubmit(async () => {
const formFieldValues = $w(“#form1”).getFieldValues();
var countA = 0;
let firstvalue = formFieldValues.favSubject;

if(firstvalue == “English”)
formFieldValues.finalAnswer = “Shakespeare”;

});

Hi, @aditi_harlalka !!

Hi ! I tried using onSubmit() on my end, and I was able to confirm that it triggers correctly when the form’s submit button is clicked. In your case as well, I believe wrapping the code inside onReady() should make onSubmit() work as expected. My guess is that the issue might be caused by trying to attach onSubmit() before the form element is fully available on the page, which could result in the event not being triggered. :thinking:

Also, regarding whether onSubmit() allows you to modify the form data right before submission—honestly, I’m not entirely sure. I initially assumed it was a convenient hook for changing values just before sending the data, but after reading your question, I started to think that maybe it’s intended for a different use. I did a quick test myself, and it didn’t seem possible to modify the values right before submission (though I haven’t explored it thoroughly yet, so maybe there is a way :upside_down_face:).

So if your goal is to reliably modify the data before submission, I’d recommend not using the default form submit button. Instead, you could create a custom button and handle everything in its onClick() event. There, you can update the form values as needed and then use submit() to actually send the form. That might be a more dependable approach for now. :innocent: