I have an email subscription form. All I want to do is to add the email at the end of the link the signup button redirects to (after saving the subscribers). I added this on the onChange handler, but it is not firing when user types in in the box. It only fires after clicking the signup button once, which means for the signup button to work, it needs to be clicked again.
How do I get the onChange button to actually fire when needed? The onkeypress handler works fine and is triggered when using the exact same way as the onChange handler.
I would appreciate some help as I’ve already wasted hours on this and it’s such a small, small task!!
You should post your code.
But I’d guess that in your case the problem is that user is still focus on the userInput while clicking the submit, and therefore once the user clicks the button it hasn’t been changed yet.
One way to handle it, is to add a 10ms timeout before you save the data.
(Another way, is to add another checkbox “I confirm”. Once the “I confirm” is checked, enable the submit button)
I’m nut sure I understand your issue, if you add an onChange() event handler to a user input element the function will be triggered after you click outside the element.
Yes, that is the issue. I would have thought the OnChnage would be triggered with the value change.
How would the timeout work in this case?
I attached the code, but literally I even only want this to be triggered:
export function input1_change(event) {
console.log(event.target.value);
}
@jonatandor35 I did not add code to the button for onClick - I want it to do what it usually does, then redirect to the link that I set it to in the inputChange. ( or this is what I would like to do).
I was trying to not have to handle the submit of the form with saving the dataset myself to the subscribers list, and redirect the user when this would already automatically happen from wix.
Something like this:
If not, then you don’t need any time out, just something like:
import wixLocation from 'wix-location';//at the top of the page code
//code
$w("#dataset1").onAfterSave( () => {
wixLocation.to(urlToRedirect + $w("#input1").value);
} );
@laura59248 I don’t know. the Forms App is quite limited, and not all the forms are the same, and I can’t give you code that will work on all of them for sure.
@laura59248 if you don’t save it to the dataset, you won’t be able to use .onAfterSave().
But you can, for example, redirect to the other page onViewportEnter() of success notification.