fdietze / formidable   0.1.6

GitHub

Automatic Form Derivation for Outwatch

Scala versions: 3.x 2.13
Scala.js versions: 1.x

Formidable

Generates reactive HTML forms directly from type definitions. These forms can be used with ScalaJS and Outwatch and the generated HTML/CSS is fully customizable. Scala 2.13 and 3 are supported. Here's a Demo and it's Code.

libraryDependencies += "com.github.fdietze" %%% "formidable" % "<version>"
import outwatch._
import outwatch.dsl._
import colibri.reactive._

import formidable._

case class Person(name: String, age: Option[Int])

val state:Var[Person] = Form.state[Person]

div(
  Form[Person].render(state),
  div(state.map(_.toString)),
)

Formidable defines a typeclass Form[T] with many default instances:

  • Primitives: Int, Double, Long, String, Boolean
  • Option[T]
  • Seq[T], Vector[T], List[T]
  • sealed traits
  • tuples
  • case classes
  • recursive types
  • generic types

Automatic derivation is achieved using Magnolia.