Field

io.eezo.http.Field
See theField companion object
final class Field[X](val inputType: String, write: X => String, ticked: X => Boolean = ...)(using evidence$1: Parser[X])

One case class field, as HTML sees it.

Deliberately not db's Column, which is PreparedStatement and ResultSet and nothing else. A model with no database behind it still has to form, and Login(email, password) is the case that proves it: it will never be a table, and it renders and parses like anything else.

Composed over a io.eezo.core.Parser rather than being one, because how text becomes a value is not a form's question: a configuration value asks it too, from a module that never sees a browser. What a Field adds is only what an input needs, its type, its shown text and whether it renders ticked. It does not extend Parser, so a Field can never stand where a Parser is asked for, and a checkbox's lenient reading of on cannot leak into anything that is not a form.

A final class rather than a trait, so the reading has one place to live and a hand written instance cannot override read past its Parser. Field.of is how an author writes one.

absent comes from the Parser, and it is why a browser's habits need no hidden inputs here. A browser omits an unchecked checkbox entirely rather than submitting false, so "the key is missing" has to be answerable per type. Rails answers it by rendering a hidden companion input before every checkbox and then relying on last wins; that is a second mental model, and a value the server cannot distinguish from a genuine submission. Here Field[Boolean].absent is Some(false), Field[Option[X]].absent is Some(None), and everything else is None, which is exactly the set of fields that can report "is required".

Attributes

Companion
object
Source
Field.scala
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

def absent: Option[X]

The value to use when the key is not in the submission at all, if there is one.

The value to use when the key is not in the submission at all, if there is one.

Attributes

Source
Field.scala
def checked(x: X): Boolean

Whether a checkbox holding x renders ticked. Only a field that renders as a checkbox has anything to say, so every other one is never ticked.

Whether a checkbox holding x renders ticked. Only a field that renders as a checkbox has anything to say, so every other one is never ticked.

Attributes

Source
Field.scala
def parser: Parser[X]

Public so a Field built over another can compose over the same reading, rather than summoning a Parser of its own that may read differently, as the core Boolean does.

Public so a Field built over another can compose over the same reading, rather than summoning a Parser of its own that may read differently, as the core Boolean does.

Attributes

Source
Field.scala
def read(text: String): Either[String, X]

Reads submitted text through the Parser. The message is what reaches the user, so it reads as a predicate about the value rather than as a parser's complaint.

Reads submitted text through the Parser. The message is what reaches the user, so it reads as a predicate about the value rather than as a parser's complaint.

Attributes

Source
Field.scala
def show(x: X): String

The field's value as text: what an input is filled with, and what a show page or an index prints. A checkbox has no text to fill, so Form.render asks checked instead.

The field's value as text: what an input is filled with, and what a show page or an index prints. A checkbox has no text to fill, so Form.render asks checked instead.

Attributes

Source
Field.scala

Concrete fields

val inputType: String

Attributes

Source
Field.scala