Skip to content

Commit

Permalink
feat(framework): prevent forms without [action] from submiting
Browse files Browse the repository at this point in the history
Prevent forms without an `action` to submit. This is good practice adopted from angular.
  • Loading branch information
Alxandr committed Feb 20, 2015
1 parent 7696d41 commit a580525
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/aurelia.js
Expand Up @@ -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;
Expand Down Expand Up @@ -121,6 +130,8 @@ export class Aurelia {

this.started = true;
logger.info('Aurelia Starting');

preventActionlessFormSubmit();

var resourcesToLoad = this.resourcesToLoad;
this.resourcesToLoad = [];
Expand Down Expand Up @@ -175,4 +186,4 @@ export class Aurelia {
return this;
});
}
}
}

0 comments on commit a580525

Please sign in to comment.