Skip to content

Commit

Permalink
Fixes #6, form values are now attached to a values object that is on …
Browse files Browse the repository at this point in the history
…the routes handler. - note I didn't place it on the params object as that is reserved for url parameters
  • Loading branch information
PaulKinlan committed May 31, 2011
1 parent 68dbc71 commit 04148f0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
10 changes: 5 additions & 5 deletions examples/client/post-example1/example.html
Expand Up @@ -7,8 +7,7 @@
var app = new routes(); var app = new routes();


app.post('post.html', function(e) { app.post('post.html', function(e) {

alert('Captured the POST, value = ' + e.values.test);
alert('Captured the POST');
return false; return false;
}); });
</script> </script>
Expand All @@ -18,18 +17,19 @@
<p>This is an example of capturing a POST, we have two forms, the 1st will be intercepted by the framework, the 2nd will not and will be passed through to the server</p> <p>This is an example of capturing a POST, we have two forms, the 1st will be intercepted by the framework, the 2nd will not and will be passed through to the server</p>
<pre><code>var app = new routes(); <pre><code>var app = new routes();


app.get('post.html', function() { app.get('post.html', function(e) {
alert('Captured the POST, value = ' + e.values.test);
});</code></pre> });</code></pre>


<form action="post.html" method="post"> <form action="post.html" method="post">
<p>This will be handled by LeviRoutes.</p> <p>This will be handled by LeviRoutes.</p>
<input type="test" placeholder="Enter something here"> <input type="text" name="test" placeholder="Enter something here">
<input type="submit"> <input type="submit">
</form> </form>


<form action="post2.html" method="post"> <form action="post2.html" method="post">
<p>This will be handled by the server.</p> <p>This will be handled by the server.</p>
<input type="test" placeholder="Enter something here"> <input type="text" name="test" placeholder="Enter something here">
<input type="submit"> <input type="submit">
</form> </form>


Expand Down
12 changes: 11 additions & 1 deletion routes.js
Expand Up @@ -51,8 +51,18 @@ var routes = function() {
var group = route.regex.groups[g]; var group = route.regex.groups[g];
params[g] = routeMatch[group + 1]; params[g] = routeMatch[group + 1];
} }

var values = {};
if(e.target instanceof HTMLFormElement) {
var form = e.target;
var items = form.length;
var item;
for(var j = 0; item = form[j]; j++) {
if(!!item.name) values[item.name] = item.value;
}
}


route.callback({"url": url, "params": params, "e": e}); route.callback({"url": url, "params": params, "values" : values, "e": e});
return true; return true;
} }


Expand Down

0 comments on commit 04148f0

Please sign in to comment.