Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #861 (closed enhancement: wontfix)

Opened 3 years ago

Last modified 2 years ago

[RESEARCH] client-side JavaScript validation

Reported by: sebastian.kanthak@muehlheim.de Assigned to: David
Priority: normal Milestone:
Component: ActionPack Version: 0.10.0
Severity: normal Keywords: validation
Cc: eastcoastcoder@gmail.com

Description

The goal of this patch is to support automatic generation of client-side JavaScript validation in addition to server-side validation.

The high-level design is as follows:

  • We introduce reflection for validations so that we can examine what validations have been defined
  • We store InstanceTag objects for all fields generated via FormHelper's methods in a @rails_instance_tags attribute of the view
  • We provide a JS library with functions for all the supported validation types
  • We then generate appropriate JS calls for all fields in our new @rails_instance_tags attribute.

The current patch is just a proof-of-concept and only supports "validates_presence_of" and "validates_length_of with :maximum".

See the HOWTO on instructions on how to play with the patch.

Attachments

js_validation.diff (8.1 kB) - added by sebastian.kanthak@muehlheim.de on 03/17/05 23:58:45.
proof-of-concept patch for support of javascript validation
HOWTO (2.5 kB) - added by sebastian.kanthak@muehlheim.de on 03/17/05 23:59:28.
instructions on how to use javascript validation support for rails
.2 (0 bytes) - added by anonymous on 05/04/05 12:54:39.

Change History

03/17/05 23:58:45 changed by sebastian.kanthak@muehlheim.de

  • attachment js_validation.diff added.

proof-of-concept patch for support of javascript validation

03/17/05 23:59:28 changed by sebastian.kanthak@muehlheim.de

  • attachment HOWTO added.

instructions on how to use javascript validation support for rails

05/04/05 12:54:39 changed by anonymous

  • attachment .2 added.

06/09/05 18:30:18 changed by mschuerig

I'd love to see reflection on validations in Rails. On the server-side, I'm currently using a less elegant approach then the one presented here. I'll probably switch after further examination of Sebastian's patch.

On the client-side, I favor a different approach: Connect input elements and validation code purely declaratively through the class attributes of HTML elements. This works well with "semantic", high-level checks such as zipCode, date, etc., but also for different_values and other more involved stuff. I've got a working framework that I hope to publish in the next couple of days. I'll announce it on the Rails ML and here -- unless I forget to...

06/15/05 23:44:00 changed by anonymous

  • component changed from ActiveRecord to ActionPack.
  • severity changed from enhancement to critical.

06/15/05 23:45:19 changed by anonymous

  • status changed from new to closed.
  • resolution set to fixed.

07/06/05 16:03:49 changed by anonymous

  • status changed from closed to reopened.
  • resolution deleted.
  • severity changed from critical to normal.

09/13/05 17:39:55 changed by anonymous

  • cc set to eastcoastcoder@gmail.com.

09/21/05 13:32:19 changed by anonymous

Great work, but still causes a 1 to 1 mapping of ActiveRecord objects to validators. Web forms don't always correspond to active record objects (checkboxes for reading TOS or other synthesized fields). It would be great to see something more like ASP.NET where the form field validations are declarable independently.

04/12/06 20:49:33 changed by anonymous

if anyone is interested in integrating my js validation library, you're welcome to use it: http://jeffemminger.com/jvalx/

09/09/06 04:40:38 changed by bitsweat

  • status changed from reopened to closed.
  • type changed from defect to enhancement.
  • resolution set to wontfix.

Pluginize