Permalink
Browse files

Fixes #6, form values are now attached to a values object that is on …

…the routes handler. - note I didn't place it on the params object as that is reserved for url parameters
  • Loading branch information...
1 parent 68dbc71 commit 04148f0f821887863f39e484da9d3164815e38d1 @PaulKinlan committed May 31, 2011
Showing with 16 additions and 6 deletions.
  1. +5 −5 examples/client/post-example1/example.html
  2. +11 −1 routes.js
@@ -7,8 +7,7 @@
var app = new routes();
app.post('post.html', function(e) {
-
- alert('Captured the POST');
+ alert('Captured the POST, value = ' + e.values.test);
return false;
});
</script>
@@ -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>
<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>
<form action="post.html" method="post">
<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">
</form>
<form action="post2.html" method="post">
<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">
</form>
View
@@ -51,8 +51,18 @@ var routes = function() {
var group = route.regex.groups[g];
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;
}

0 comments on commit 04148f0

Please sign in to comment.