SHtml.form?

30 views
Skip to first unread message

Dennis Haupt

unread,
Jun 3, 2016, 6:51:47 AM6/3/16
to lif...@googlegroups.com
hi,

i want to create forms that can upload files.
it is impossible for me to solve this via the usual <snippet.call?form=post multipart=true> way because this can only give me a single form, but i need to generate them dynamically like this
stuff.map(data => "blah" #> theform)


how can i solve this? i would need a method like SHtml.form(content) or alternatively, get an ajax form to work with file uploads.

any ideas?

Brett Grace

unread,
Jun 3, 2016, 12:22:37 PM6/3/16
to Lift
You can use CSS selectors to generate HTML dynamically, including form elements. You can also include snippets in other snippets, they will be fully expanded, which would give you a way of generating multiple forms in a page. There are also several techniques for doing Ajax file uploads, Lift Cookbook documents a jQuery method and links to several other methods (http://chimera.labs.oreilly.com/books/1234000000030/ch05.html#_problem_51).

Dennis Haupt

unread,
Jun 3, 2016, 1:07:15 PM6/3/16
to lif...@googlegroups.com
i don't want to go any detours like creating a dummy snippet just so i can nest them just so i can get multiple forms (and then i still have to pass data around from the outer to the inner snippet)
ideally, i would have a method shtml.fileuploadcapableform(stuff) where stuff == my form elements - but i don't know what exactly to put in there to satisfy lift in such a way that the file upload works.
do you happen to know how such a method would have to look like? :D 

--
--
Lift, the simply functional web framework: http://liftweb.net
Code: http://github.com/lift
Discussion: http://groups.google.com/group/liftweb
Stuck? Help us help you: https://www.assembla.com/wiki/show/liftweb/Posting_example_code

---
You received this message because you are subscribed to the Google Groups "Lift" group.
To unsubscribe from this group and stop receiving emails from it, send an email to liftweb+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Antonio Salazar Cardozo

unread,
Jun 3, 2016, 3:17:26 PM6/3/16
to Lift
I'm not following exactly what the complication is here, but…

You can use `SHtml.makeFormsAjax andThen` in front of your
transforms to handle the AJAXification of the form. You can also
append any JS in a script tag to do whatever JS setup you want to
do, if you want. Think something like:

  "type=file" #> { input: NodeSeq =>
    input ++
    <script>setupAjaxFileUploadForm("formId")</script>
  }

You can also yield a `data-lift` directly in your bindings:

<form class="my-form-that-will-appear-many-times">
  <!-- fields -->
</form>

"form" #> myItems.map { item =>
  "^ [data-lift]" #> "Form.post?multipart=true" &
  .. other bindings ..
}

This will make one form for each item, binding it as a POST form with
multipart encoding (leave off multipart=true if you don't want to do that),
and then bind whatever other bits in the form you want to bind are.
Thanks,
Antonio
To unsubscribe from this group and stop receiving emails from it, send an email to liftweb+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages