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 on top of bind() ?
>
> > > > Anyway, great to noodle this as its certainly very important  going
> > > > forward
>
> > > > Cheers
>
> > > > Tim
>
> > > > On Sep 21, 7:44 am, Marius <[EMAIL PROTECTED]> wrote:
>
> > > > > Right ...
>
> > > > > IMHO the key things that we need to have :
>
> > > > > 1. Typesafe validation (predicates as partial functions sounds very
> > > > > good to me ;) ... )
> > > > > 2. Scala objects abstracting forms ... maybe in a way you similar with
> > > > > what presented here (also this has been mentioned in other posts)
> > > > > 3. An easy way of obtaining markup from "Form" classes
> > > > > 4. An easy way of processing the form (this is the easiest part as we
> > > > > have all we need here)
>
> > > > > I'll also do some noodling on this and let's come with concrete
> > > > > proposals.
>
> > > > > P.S.
> > > > > Some ideas are currently 
> > > > > here:http://liftweb.net/index.php/Unified_Validation
>
> > > > > Br's,
> > > > > Marius
>
> > > > > On Sep 20, 8:46 pm, Tim Perrett <[EMAIL PROTECTED]> wrote:
>
> > > > > > Guys,
>
> > > > > > Myself and Marius have just been talking over IM about generic ways 
> > > > > > to
> > > > > > build validation into lift.
>
> > > > > > IMHO, right now it seems that there is not any cohesive way to
> > > > > > validate user input (without a bunch of manual coding). One of the
> > > > > > things we talked about is server-side form representation... I 
> > > > > > wonder
> > > > > > if there is a way to abstract form building so that it was somehow
> > > > > > generic and let you specify field content & type and also the
> > > > > > validation that needs to be applied to that control.
>
> > > > > > This just pure spitballing, but what about something like:
>
> > > > > > class MyDemoFrom extends LiftForm {
> > > > > >   def someInput = TextInput(SHtml.text(<usual stuff>), Validatons({
> > > > > >     // whatever validation here
> > > > > >   }))
>
> > > > > > }
>
> > > > > > Or whatever - I just want to try and talk through the idea rather 
> > > > > > than
> > > > > > propose code at this stage. Even when we extract the validation 
> > > > > > stuff
> > > > > > from mapper, we'll still need some way of implementing those
> > > > > > validation constraints on controls wont we?
>
> > > > > > Interesting in what people think
>
> > > > > > Cheers
>
> > > > > > Tim
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to