You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In some cases, you may want to conditionally prevent form submission based on client-side validation or other business logic before allowing a `phx-submit` to be processed by the server.
415
+
416
+
JavaScript can be used to prevent the default form submission behavior, for example with a [hook](js-interop.md#client-hooks-via-phx-hook):
417
+
418
+
```javascript
419
+
/**
420
+
* @type{import("phoenix_live_view").HooksOptions}
421
+
*/
422
+
let Hooks = {}
423
+
Hooks.CustomFormSubmission= {
424
+
mounted() {
425
+
this.el.addEventListener("submit", (event) => {
426
+
if (!this.shouldSubmit()) {
427
+
// prevent the event from bubbling to the default LiveView handler
428
+
event.stopPropagation()
429
+
// prevent the default browser behavior (submitting the form over HTTP)
0 commit comments