How do I prevent an on.submit event from changing/

2019-01-20 11:28发布

问题:

In Javascript when I provide an onSubmit function, and I return 'false' from the function, it prevents the page from changing/reloading.

However in Dart the onSubmit.listen(...) function does not take a return type.

How do I stop the submit from sending the form data and changing/reloading the page?

回答1:

Within the on.submit.add(...) callback, you will receive the Event as an argument. The Event object provides a preventDefault() method to prevent or cancel the default action.

It can be used as follows:

querySelector('#myForm').onSubmit.listen((Event e) {
  // ... your code here
  e.preventDefault();
});


标签: dart