lift-formality 1.0.0 released

71 views
Skip to first unread message

Antonio Salazar Cardozo

unread,
Nov 14, 2016, 5:45:48 PM11/14/16
to Lift
Hey folks,
Just released lift-formality 1.0.0. It's got a lot of tidbits to it; see the release
announcement for more. Most importantly, we're now using it in production
at Elemica, so as we run into issues we'll be addressing them.

Currently it's only for Lift 2.6 and Scala 2.11, but I'll be working to fix that
hopefully by the end of the year.

I'll drop a slightly simplified version of the first form that Ari built using lift-formality
here for fun:

    val processingMode =
      selectField[ProcessingMode](
        ".upload-processing-mode",
        processingModes,
        asRadioButtons = true
      ) ? { mode: Box[ProcessingMode] =>
        mode match {
          case Full(_) => Empty
          case _ => Full(S ? "validation.notEmpty")
        }
      }
    val connectionGroup = field[String]("#connection-configuration-value") ? notEmpty
    val uploadedFileField = fileUploadField("#message-file-upload")
    val pastedTextField = field[String]("#paste-message")

    val inboundConfigurationIdGroup =
      fieldGroup(".inbound-configuration").withFields(
        processingMode,
        connectionGroup
      ).withBoxedConverter { (processingMode: Box[ProcessingMode], connectionGroupId: Box[String]) =>
        for {
          mode <- processingMode
          connectionGroupId <- connectionGroupId
          connectionGroup <- ConnectionGroup.get(connectionGroupId)
          inboundGroup <- connectionGroup.inboundConnectionModeGroup
          configurationId <- Box(inboundGroup.getConfigurationIdForProcessingMode(mode)) ?~ (S ? "messageSubmission-configurationNotAvailableForMode") ~> "inbound-configuration"
        } yield {
          configurationId
        }
      }

    val messageContentGroup =
      fieldGroup(".upload-message-container").withFields(
        uploadedFileField,
        pastedTextField
      ).withBoxedConverter { (file: Box[FileParamHolder], text: Box[String]) =>
        val textBytes = text.filter(! _.isEmpty).map(_.getBytes(Charsets.UTF_8))
        val fileBytes = file.map(_.file)

        textBytes or fileBytes match {
          case empty: EmptyBox =>
            S.error("upload-message-container", S ? "submitMessageModal-mustHaveEitherFileOrMessage")
            Empty
          case bytes =>
            bytes
        }
      }

    val messageSubmissionForm =
      form withAjaxFields(
        inboundConfigurationIdGroup,
        messageContentGroup
      ) onSuccess { (inboundConfigurationId, messageContent) =>
        handleSubmitResult(submitMessage(inboundConfigurationId, messageContent))
        MessageProcessed
      }

    "form" #> messageSubmissionForm.binder

Enjoy!
Thanks,
Antonio

Joe Barnes

unread,
Nov 20, 2016, 10:52:28 PM11/20/16
to Lift
I'm really excited about how this can be used to not only clean up form creation, but it can make dumb forms and ajax forms use the same code. This will be solid when combined with the VDOM stuff.

Joe

Antonio Salazar Cardozo

unread,
Nov 21, 2016, 9:10:47 AM11/21/16
to Lift
Just need to figure out the display of validation errors for “dumb” forms. Still
thinking about that one in the back of my head... There's some potential complications
there for sure.

Should be able to cook something up though ;)
Thanks,
Antonio

Matt Farmer

unread,
Nov 21, 2016, 12:14:43 PM11/21/16
to Lift
That code snippet tho. 😍


Matt Farmer | Blog | Twitter
GPG: CD57 2E26 F60C 0A61 E6D8  FC72 4493 8917 D667 4D07

--
--
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.

ari gold

unread,
Nov 29, 2016, 1:04:49 PM11/29/16
to Lift
Oh yeah!

That relatively-small snippet does quiiiiite a bit too... POWAH!

Kudos to ya for busting it out - especially those boxed converter bits that proved oh so handy :)

 Ari
Reply all
Reply to author
Forward
0 new messages