From a58052571281cce001089bc065858e47ee595874 Mon Sep 17 00:00:00 2001 From: Alxandr Date: Fri, 20 Feb 2015 01:39:27 +0100 Subject: [PATCH] feat(framework): prevent forms without [action] from submiting Prevent forms without an `action` to submit. This is good practice adopted from angular. --- src/aurelia.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/aurelia.js b/src/aurelia.js index 7989bb97..3db3b291 100644 --- a/src/aurelia.js +++ b/src/aurelia.js @@ -24,6 +24,15 @@ if (!window.CustomEvent || typeof window.CustomEvent !== 'function') { window.CustomEvent = CustomEvent; } +function preventActionlessFormSubmit() { + document.body.addEventListener('submit', evt => { + const target = evt.target; + const action = target.action; + if (target.tagName.toLowerCase() === 'form' && !action) + evt.preventDefault(); + }); +} + function loadResources(container, resourcesToLoad, appResources){ var resourceCoordinator = container.get(ResourceCoordinator), current; @@ -121,6 +130,8 @@ export class Aurelia { this.started = true; logger.info('Aurelia Starting'); + + preventActionlessFormSubmit(); var resourcesToLoad = this.resourcesToLoad; this.resourcesToLoad = []; @@ -175,4 +186,4 @@ export class Aurelia { return this; }); } -} \ No newline at end of file +}