Hi,

Ross, thank you for your help. This code works perfectly for me. I
heaven't noticed I could group many elements in one lift tag.

I changed somethings in your code. Maybe it's not worth mentioning but
if someone has similar problems it can help a little.
I corrected only to things: changed parameters order in one bind and
added some code to other.
Result is here:

    def newPlace(ns: NodeSeq, place : Place): NodeSeq = {
        def bindFields(innerNs: NodeSeq): NodeSeq = {
            var s : String = "test"
            signupFields.
            map(fi => getSingleton.getActualBaseField(place, fi)).
            flatMap(f => {
                    f.toForm.toList.map(form => {
                                                    bind("field",
innerNs,
                                                        "displayName" -
> f.displayName,
                                                        "form"        -
> form)(1);
                                                })
                })
        }

        def handleSubmit(): Any = {
        }

        bind("place", ns,
             "fields" -> { (ns: NodeSeq) => bindFields(ns) },
             "submit" -> { (ns: NodeSeq) => SHtml.submit("Submit new
place", handleSubmit _) })
    }

Still I don't get why I need to get second element from bind result
(which is NodeSeq) and pass it to .toForm.toList.map(...).
When I first compiled this code i got type mismatch error:
 found   : scala.xml.NodeSeq
 required: scala.xml.Node

So I picked up first non empty element from the result by using bind
(...)(1) and it works in my scenario. Maybe I will catch it later ;)

Again this code works perfectly for me. Great thanks Ross!

- Martin




On 24 Wrz, 16:15, Ross Mellgren <dri...@gmail.com> wrote:
> It sounds like you probably want <p>{ SHtml.submit("Title of submit  
> button", () => actionToTakeWhenButtonIsUsedToSubmitForm) }</p>
>
> By the way, what you have there doesn't seem to be following the usual  
> lift pattern of binding snippets, is there a reason that you prefer  
> this to:
>
> template:
>
> <lift:MySnippet.newPlace form="post">
>      <h4>Place details</h4>
>      <div>
>          <place:fields>
>              <p>
>                  <label><field:displayName /></label>
>                  <field:form />
>              </p>
>          </place:fields>
>      </div>
>      <p><place:submit /></p>
> </lift:MySnippet.newPlace>
>
> Snippet:
>
> def newPlace(ns: NodeSeq): NodeSeq = {
>      val place = /* make a new place somehow */
>
>      def bindFields(ns: NodeSeq): NodeSeq =
>          signupFields.
>              map(fi => getSingleton.getActualBaseField(place, fi)).
>              flatMap(f => {
>                  f.toForm.toList.map(form => {
>                      bind(ns, "field",
>                           "displayName" -> f.displayName,
>                           "form"        -> form)
>                  })
>              })
>
>      def handleSubmit(): Any = /* do something with place */
>
>      bind("place", ns,
>           "fields" -> { (ns: NodeSeq) => bindFields(ns) },
>           "submit" -> { (ns: NodeSeq) => SHtml.submit("Submit new  
> Place", handleSubmit _) })
>
> }
>
> This way lets you see most of the HTML in one place (the template). I  
> inlined localForm, but there's no particular reason that it needs to  
> be local (other than it closes on place, but you could just pass that  
> in)
>
> -Ross
>
> On Sep 24, 2009, at 6:55 AM, Martin wrote:
>
>
>
> > Hi all,
>
> > I've got a following problem. When I create a form form automaticly..
> > similar to the User login/register example I encontered a problem I'm
> > not posible to cope with.
>
> > Firstly I have 'written' a function (using Copy&Paste method) which
> > creates a form fields list based on my class properties:
>
> >    private def localForm(place: Place, ignorePassword: Boolean):
> > NodeSeq = {
> >        signupFields.
> >        map(fi => getSingleton.getActualBaseField(place, fi)).
> >        filter(f => !ignorePassword || (f match {
> >                    case f: MappedPassword[Place] => false
> >                    case _ => true
> >                })).
> >        flatMap(f =>
> >            f.toForm.toList.map(form => <p><label>{f.displayName}</
> > label> {form}</p>) )
> >    }
>
> > Next, I wrote some code to return a complete form to the snippet:
>
> >    def newPlace(place: Place) =
> >    <form method="post" action={S.uri}>
> >        <h4>Place details</h4>
> >        <div>
> >            {
> >                localForm(place, false)
> >            }
> >        </div>
> >        <p><_WHAT_SHOULD_I_WRITE_HERE_:submit /></p>
> >    </form>
>
> > My question is... what do I write in _WHAT_SHOULD_I_WRITE_HERE_ ?
> > Or better.. how/where to define this value?
>
> > In a user login/register example there is submit defined like this:
> > <user:submit>
>
> > Placing there name of the owner class didn't work.
> > I know I could use bind but as far as I know next I should create a
> > complete snippet with all the fields by hand.. and I would to avoid
> > it.
>
> > I was digging for solution in a Lift Book and on group as well, but
> > without success.
> > Help!

--~--~---------~--~----~------------~-------~--~----~
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 
liftweb+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to