Validation via S

From Lift

Jump to: navigation, search

I'm into keeping things simple, so my first idea is to keep things relatively low level. I'm still figuring out lift, so please forgive any mistakes or if I've overlooked functionality that already exists. Currently the way I've done things for form input is to use the S.text and related functions to generate the input field and bindings. From what I gather, S.text (and maybe S.password) are probably the most likely candidates for validation support, although it would be nice if we could support more complex validation of the whole form (make sure that if radio X is selected then the foo input is numeric and >= 6, for instance). I'm thinking we could have a DSL for validation that we could use to define the validation for a particular element as well as for the S.submit (whole form) so that the resulting code could be used for server-side validation as well as generation of client-side validation javascript. Perhaps as an optional parameter on the form generation:

S.text(value: String, func: String => Any, validator: Validation, params: FormElementPieces*)
S.submit(value: String, func: String => Any, validator: Validation, params: FormElementPieces*)

I'm just starting to read up on piecing together a DSL in Scala, but I think it would be nice to be able to say something like:

numeric and > 7.2 and < 13 else "Please enter a valid foobaz value"

Or

length < 200 else "Your name cannot possibly be that long"

The validator could wrap the bind function and either pass the validated string down to it, or return the else statement as a form error. At the same time, it could generate onsubmit code to validate the form on the client side if configured.

Personal tools