Formlets

26
FORMLETS A better way to create forms?

Transcript of Formlets

Page 1: Formlets

FORMLETSA better way to create forms?

Page 2: Formlets

FORMS

• Forms are used to accept input from the user

• Forms benefit from structure and predictability

• Forms should provide feedback to the user on the data quality (validation)

• Once sufficient quality is reached the user submits the data

• Some applications may have 100+ different forms

Page 3: Formlets
Page 4: Formlets
Page 5: Formlets

TextBox

TextBox

TextBox

TextBox

TextBox

TextBox

CancelSubmit

Page 6: Formlets

TextBox

TextBox

TextBox

TextBox

TextBox

TextBox

CancelSubmit

Page 7: Formlets
Page 8: Formlets

Design Patterns to the rescue?

Page 9: Formlets
Page 10: Formlets
Page 11: Formlets
Page 12: Formlets
Page 13: Formlets
Page 14: Formlets
Page 15: Formlets

Formlets

Composable UI Inputs

Page 16: Formlets

Formlet<string>

TextBox string

Page 17: Formlets

Formlet<string * string>

TextBox * TextBox string * string

Page 18: Formlets

FORMLETS

• We need some kind of flexible way to bind two Formlets into a new Formlet

• As the result of the binding operation is a Formlet the result can be bound as well

• This gives endless composability

• Like integers are composable: 1 + 2 + 3 + 4

• Like IEnumerables are composable: l.Select (...).Where (...).OrderBy ()

• Our Formlets are composable: TextBox + TextBox + TextBox + TextBox

Page 19: Formlets

Demo

Page 20: Formlets

Formlets

Composable UI Inputs

Page 21: Formlets

“Formlets are a way of building

[HTML] forms that are type-safe,

handle errors, abstract and are easy to

combine into bigger forms”

Haskell Wiki

Page 22: Formlets

“The key feature of formlets is that

they are composable”

Formaggio

Page 23: Formlets

Formlets

Composable UI Inputs

Page 24: Formlets

function notEmpty(lbl: string): IFormlet<string> {

return enhanceWithLabel(lbl, enhanceWithErrorVisualizer(

ensureNotEmpty(input(""))))

}

function createAddress(vs: string[]): IAddress;

function address(lbl: string): IFormlet<IAddress> {

return enhanceWithGroup(lbl, map(createAddress, many(

[

notEmpty("Street"),

notEmpty("Zip"),

notEmpty("City"),

notEmpty("State")

])))

}

let invoiceAddress = address("Invoice Address")

Page 25: Formlets

LINKS

• WebSharper Formlets

• http://websharper.com/docs/formlets

• WebSharper Piglets

• http://websharper.com/docs/piglets

• WPF Formlet gist

• https://gist.github.com/mrange/f5fbc34da14b34d4064f536de60e026b

• Great Scott!

• http://www.slideshare.net/ScottWlaschin/railway-oriented-programming

• http://www.slideshare.net/ScottWlaschin/fp-patterns-ndc-london2014

• The essence of Form Abstraction (Wadler obviously)

• http://homepages.inf.ed.ac.uk/wadler/papers/formlets-aplas/formlets-aplas.pdf

Page 26: Formlets

Questions?