Skip to content

Instantly share code, notes, and snippets.

@adamw
Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamw/5f68795f90b34abf7df1 to your computer and use it in GitHub Desktop.
Save adamw/5f68795f90b34abf7df1 to your computer and use it in GitHub Desktop.
Supler actions
def carForm(removeAction: Car => ActionResult[Car]) = form[Car](f => List(
f.field(_.make).possibleValues(_ => carMakesAndModels.keys.toList).label("Make"),
// etc.
// trait Form[T] { def action(T => ActionResult[T]): Row[T] }
f.action(removeAction).label("Delete")
))
val personForm = form[Person](f => List)
f.field(_.firstName).label("label_person_firstname"),
// etc.
f.subform(_.cars, carForm(f.parentAction((person, index, car) => person.removeCar(index))))
.label("Cars").renderHint(asList()),
))
/*
f.parentAction może być użyte tylko w f.subform (sprawdzane przy kompilacji) i jest przez makro rejestrowana akcja w SubformFieldzie
f.parentAction: ((Person, Int, Car) => ActionResult[Person]) => (Car => ActionResult[Car])
ActionResult jest po to żeby potem "odpalić" wszystkie akcje i odpowiednio pozmieniać pola w parentach itd.
(może być wielokrotnie zagnieżdżone)
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment