[Lift] Re: Validations, Server side controls etc

2008-09-21 Thread Marius

Kind of funny ... we were writing almost in parallel :)


On Sep 21, 9:30 pm, Tim Perrett [EMAIL PROTECTED] wrote:
 WOW! Marius this is so fricking sweet. well done, awesome stuff
 indeed!

 Functionally, I think this would serve as an excellent place to start
 for providing validation in lift right?

Well it's just an idea that I think it would worth to explore.

Perhaps by providing
 convenience methods for common validations rather than needing to code
 it explicitally.

That would be sweet ! ... anything particular in mind? ... things like
email, phone number validation etc?


 What other stuff do you think its missing? I have only had a quick
 play with your same, but it looks to be really great :)

Yes of course ... implement other form fields ALL form input types +
what you very well suggested : common validations for say most
frequently used validations. Shoul also work for Ajax/json forms since
notices work just fine in such situations just a bit more noodling,
testing etc.


 Cheers

 Tim

 On Sep 21, 11:58 am, Marius [EMAIL PROTECTED] wrote:

  Ok ...

  I just uploaded an example 
  applicationhttp://groups.google.com/group/liftweb/web/liftform.tar.gz

  At the first glance it may look complicated but it's really not. For
  instance we have this snippet class

  class Form {
object  who extends RequestVar(0)
object  sec extends RequestVar(-1)

  val form: LiftForm = new LiftForm(TextField({(v: Int) =
  println(who is  + v); who(v toString)}, FieldType.INT)
  ({case v if v  10 = },
  ValidationMessage(who_msg, {
  case v = who(v);
  Text(* The value must be a number greater then 10.)
})),

TextField({(v: Float) =
  println(sec is  + v); sec(v toString)}, FieldType.FLOAT)
  ({case v if v = 0.7f = },
  ValidationMessage(sec_msg, {
  case v = sec(v);
  Text(* The value must be a number smaller then 0.7.)
}))
   )

def validate(html: Group) : NodeSeq = {

  bind(hello, html,
   whoField  - form.getFields(0).toHtml(who) % (size - 30)
  % (id - whoField),
   secField - form.getFields(1).toHtml(sec) % (size -
  30) % (id - secField),
   submit - submit(Submit, {println(IN SUBMIT);
  S.notice(FORM IS VALID  + form.passedValidation); })
  )

}

  We have a LiftForm reference that contains two FormField-s in
  particular case 2 TextField's

  TextField({(v: Int) = println(who is  + v); who(v toString)},
  FieldType.INT)
  ({case v if v  10 = },
  ValidationMessage(who_msg, {
  case v = who(v);
  Text(* The value must be a number greater then 10.)
}))

  TextField here is the companion module of the TextField class. It
  takes:

  1. The function that is called for this field when the form is
  submitted and validation passed: {(v: Int) = println(who is  + v);
  who(v toString)}
  2. The field type. This FieldType is an enum that knows how to convert
  from the request string to a particular type.
  3. A tuple holding:
 3.1 The actual validation predicate expressed as a PartialFunction
 3.2. The ValidationMessage which holds the id of the notice element
  (basically where we want the error validation message to appear) and a
  function that receives the original request string and returns a Node
  which impersonates the actual error message

  Thoughts are more then welcomed !

  P.S.
  Currently for exemplification only TextField is implemented but we can
  easily extend it to all possible form fields.

  Br's,
  Marius

  On Sep 21, 1:28 pm, Marius [EMAIL PROTECTED] wrote:

   Actually I just Implemented a small lift app that does typesafe form
   validation on server side.

   I'll attach it in a bit ... it's just an idea

   Br's,
   Marius

   On Sep 21, 1:08 pm, Tim Perrett [EMAIL PROTECTED] wrote:

Sounds good Marius - project wise though we need to address this IMHO;
as we pick up more users of lift people will want this functionality
for sure.

I guess we really need to decide at what level we want to apply
validation - Im not sure that having it tightly coupled to the
persistence tier (a la rails) is a great idea. Just had a quick look
at OVal i think a generic approach like that would be good as then
your just dealing with a single methodology to spec validation
criterion on any object.

Also, conceptually, a server side representation of a form seems to be
a different notion to the bind() style we have with snippets. Im not
sure how we could get it to work in a clean way - would it be an
abstraction 

[Lift] Re: Validations, Server side controls etc

2008-09-21 Thread Tim Perrett

Great minds Marius - you sent your mail at 19:29, and mine at 19:30!
What do you think on my comments above?

Cheers, Tim

On 21 Sep 2008, at 19:29, Marius wrote:


 Guys please try running the application above, take a look on the code
 and have feedback. Is it a sufficient paradigm (from server side
 validation perspective), is it a simple enough approach from your
 perspective? ... of course it is just a draft.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Lift group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~--~~~~--~~--~--~---



[Lift] Re: Validations, Server side controls etc

2008-09-21 Thread Marius

I thought I replied :)

On Sep 21, 9:37 pm, Tim Perrett [EMAIL PROTECTED] wrote:
 Great minds Marius - you sent your mail at 19:29, and mine at 19:30!
 What do you think on my comments above?

 Cheers, Tim

 On 21 Sep 2008, at 19:29, Marius wrote:



  Guys please try running the application above, take a look on the code
  and have feedback. Is it a sufficient paradigm (from server side
  validation perspective), is it a simple enough approach from your
  perspective? ... of course it is just a draft.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Lift group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~--~~~~--~~--~--~---



[Lift] Re: Validations, Server side controls etc

2008-09-21 Thread Tim Perrett

 That would be sweet ! ... anything particular in mind? ... things like
 email, phone number validation etc?

Totally - nothing crazy to begin with, perhaps with some way of
passing a regex or whatever to ward off boiler plate code thats
repeated by lift users. Conceptually, I think the ones given by
http://validatable.rubyforge.org/ are quite nice. Like I said, nothing
crazy, but very functional... e.g. validates_format_of

 Yes of course ... implement other form fields ALL form input types +
 what you very well suggested : common validations for say most
 frequently used validations. Shoul also work for Ajax/json forms since
 notices work just fine in such situations just a bit more noodling,
 testing etc.

Exactly - this is very nice and something that IMO, lift has really
been missing. Do you mind if I take your example and extend it and
stick it into lift core? Actually thats a good point where within
the lift code base would this best sit? Probably net.liftweb.util
maybe?

Cheers

Tim
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Lift group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~--~~~~--~~--~--~---



[Lift] Re: Validations, Server side controls etc

2008-09-21 Thread Marius



On Sep 21, 9:48 pm, Tim Perrett [EMAIL PROTECTED] wrote:
  That would be sweet ! ... anything particular in mind? ... things like
  email, phone number validation etc?

 Totally - nothing crazy to begin with, perhaps with some way of
 passing a regex or whatever to ward off boiler plate code thats
 repeated by lift users. Conceptually, I think the ones given 
 byhttp://validatable.rubyforge.org/are quite nice. Like I said, nothing
 crazy, but very functional... e.g. validates_format_of

  Yes of course ... implement other form fields ALL form input types +
  what you very well suggested : common validations for say most
  frequently used validations. Shoul also work for Ajax/json forms since
  notices work just fine in such situations just a bit more noodling,
  testing etc.

 Exactly - this is very nice and something that IMO, lift has really
 been missing. Do you mind if I take your example and extend it and
 stick it into lift core? Actually thats a good point where within
 the lift code base would this best sit? Probably net.liftweb.util
 maybe?

Could you create a different git branch ? ... I'd rather wait until it
is very close to completion (from the framework perspective at least)
and then commit it into master branch. I welcome you to continue with
implementation in this branch and I will provide feedback (with either
comments and code). When we're done with it we present to the
community an example application and then put it in the master branch
after we get the lift committers consensus and hopefully other
people's fedback.

I think net.liftweb.http.form package sounds reasonable for this
framework.



 Cheers

 Tim
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Lift group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~--~~~~--~~--~--~---



[Lift] Re: Validations, Server side controls etc

2008-09-21 Thread Tim Perrett

Sorry I should have been clearer... Of course, I wouldnt work it
straight into master :-)

I'll make a branch or fork then we'll go from there

Cheers Marius, this is great work

Tim

On Sep 21, 7:57 pm, Marius [EMAIL PROTECTED] wrote:
 On Sep 21, 9:48 pm, Tim Perrett [EMAIL PROTECTED] wrote:



   That would be sweet ! ... anything particular in mind? ... things like
   email, phone number validation etc?

  Totally - nothing crazy to begin with, perhaps with some way of
  passing a regex or whatever to ward off boiler plate code thats
  repeated by lift users. Conceptually, I think the ones given 
  byhttp://validatable.rubyforge.org/arequite nice. Like I said, nothing
  crazy, but very functional... e.g. validates_format_of

   Yes of course ... implement other form fields ALL form input types +
   what you very well suggested : common validations for say most
   frequently used validations. Shoul also work for Ajax/json forms since
   notices work just fine in such situations just a bit more noodling,
   testing etc.

  Exactly - this is very nice and something that IMO, lift has really
  been missing. Do you mind if I take your example and extend it and
  stick it into lift core? Actually thats a good point where within
  the lift code base would this best sit? Probably net.liftweb.util
  maybe?

 Could you create a different git branch ? ... I'd rather wait until it
 is very close to completion (from the framework perspective at least)
 and then commit it into master branch. I welcome you to continue with
 implementation in this branch and I will provide feedback (with either
 comments and code). When we're done with it we present to the
 community an example application and then put it in the master branch
 after we get the lift committers consensus and hopefully other
 people's fedback.

 I think net.liftweb.http.form package sounds reasonable for this
 framework.



  Cheers

  Tim
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Lift group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~--~~~~--~~--~--~---



[Lift] Re: Validations, Server side controls etc

2008-09-21 Thread David Pollak


Tim Perrett wrote:
 IMHO the form validation framework should work independently from any
 persistence related stuff ...
 

 +1
   
Right.  The Record/Field stuff is not about persistence... it's about 
richer representation of data than String/Int/Long/Date.  It's about the 
stuff that surrounds the near-bit-level representation of the data.  
See 
http://blog.lostlake.org/index.php?/archives/19-Keeping-the-meaning-with-the-bytes.html
  
Validation is part of the over-all mix.

 
   

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Lift group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~--~~~~--~~--~--~---