From 372996c9a7b604c6081806b42efa8a6e551fe612 Mon Sep 17 00:00:00 2001 From: Stuart Halloway Date: Wed, 27 Aug 2008 13:28:52 -0400 Subject: [PATCH] server side validation with updater --- app/views/examples/index.html.erb | 1 + .../server_validation_with_updater.html.erb | 19 ++++++++++++++++ prototaculous.iws | 22 ++++++++++++++++--- .../server_validation_with_updater.js | 12 ++++++++++ 4 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 app/views/examples/server_validation_with_updater.html.erb create mode 100644 public/javascripts/server_validation_with_updater.js diff --git a/app/views/examples/index.html.erb b/app/views/examples/index.html.erb index ff05dfa..c93d43c 100644 --- a/app/views/examples/index.html.erb +++ b/app/views/examples/index.html.erb @@ -3,4 +3,5 @@ diff --git a/app/views/examples/server_validation_with_updater.html.erb b/app/views/examples/server_validation_with_updater.html.erb new file mode 100644 index 0000000..d98834f --- /dev/null +++ b/app/views/examples/server_validation_with_updater.html.erb @@ -0,0 +1,19 @@ + + +

Server-Side Validation

+ +
+ + + + + + + + + + + +
What is your name? 
What is your favorite color? 
+
+ diff --git a/prototaculous.iws b/prototaculous.iws index da49d70..38c05fb 100644 --- a/prototaculous.iws +++ b/prototaculous.iws @@ -68,10 +68,19 @@ - + - + + + + + + + + + + @@ -349,7 +358,14 @@ - + + + + + + + + diff --git a/public/javascripts/server_validation_with_updater.js b/public/javascripts/server_validation_with_updater.js new file mode 100644 index 0000000..c4bc2a7 --- /dev/null +++ b/public/javascripts/server_validation_with_updater.js @@ -0,0 +1,12 @@ +document.observe("dom:loaded", function() { + $("name", "favorite_color").invoke("observe", "change", function(item) { + var elem = item.element(); + console.log(elem); + new Ajax.Updater(elem.id + "_validation", "/examples/validate_field", { + method: 'post', + parameters: {field: elem.id, value: elem.value}, + onFailure: function(req) {alert(req.responseText)}, + onException: function(t,e) {alert(e);} + }); + }); +}); \ No newline at end of file