FieldHolder represents a form field that processes a value of type FieldValueType, and that can run a set of validations on the incoming field value when it is submitted.
EventHandler is a simple class that binds an event on a field to a server-side function that will be invoked with the converted value of the field whenever that event fires on the client.
EventHandler is a simple class that binds an event on a field to a server-side function that will be invoked with the converted value of the field whenever that event fires on the client. Optionally, you can also specify a function to be invoked in case the value arrives but cannot be converted to the target type.
If Full, this specifies a function that will run if the specified event triggers on the client, but the value in the field on the client cannot be converted to the expected type T. In this case, the provided function is invoked with ParamFailure that carries the error associated with the conversion failure, and whose param is the value on the client, as an unconverted String.
A FieldHolder, at its most basic, has a value that is a Box of its value type and can provide a CSS selector to transform an HTML template annotating a form field with the appropriate information to extract that value during a form submission.
Two things live here: value serializers, value converters.
Two things live here: value serializers, value converters. Value serializers are T=>String functions, value converters are String=>Box[T] functions (the round trips to/from Strings for field values).
These are all implicits so that they can be plugged into implicit resolution for FieldHolders.
This case class creates a field holder for a field that gets a FileParamHolder from the client.
This case class creates a field holder for a field that gets a FileParamHolder from the client. File upload fields behave this way.
Note that FileFieldHolders do not have value serializers: they always produce an empty string for their serialized value when setting a value on the client. It also takes no initial value for the same reason.
FormalityFormProto is the starting point for creating a formality form.
FormalityFormProto is the starting point for creating a formality form. It uses a lot of type magic, so that is going to be detailed here. At its most basic, however, it simply tracks a type-preserving list of FieldHolderBases and provides a single function, withField, to add a new such field to the form.
Once you've added all the fields you want, call formalize. This returns a FormalityForm, on which you can set success/failure/submission handlers, and which provides the facility to convert the form down to a single CssSel instance that will properly set up the form and all of its fields.
Typing discussion ---------------
shapeless lets us track our list of fields that can be String fields, Int fields, DateMidnight fields, or any other arbitrary type, while preserving those types and their order. As we build this list up, we call withField and add fields to the list one by one.
Because of what we need to do once we convert to a FormalityForm.
This case class creates a field holder for a multi select field that gets a
list of Strings
from the client.
This case class creates a field holder for a multi select field that gets a
list of Strings
from the client. If asCheckboxes
is true
, the
binder created for this select field is designed to bind to checkboxes
and their labels instead of producing a select field.
When dealing with select
elements (i.e., asCheckboxes
is false
),
the whole element specified by selector
will be replaced by a new select
element.
When asCheckboxes
is true
, the element specified by selector
will be
repeated once for each of the passed options
. The option label will be
used to set the text of the label
. If the checkbox is nested in the
label
, it will be left at the end of the label
. If a given
SelectableOption
specifies an id
attribute, in addition to that
attribute being set on the checkbox, the for
attribute of the label
element (if present) will be set to the same value.
This case class creates a field holder for a select field that gets a
String
from the client.
This case class creates a field holder for a select field that gets a
String
from the client. If asRadioButtons
is true
, the binder created
for this select field is designed to bind to radio buttons and their
labels instead of producing a select field.
When dealing with select
elements (i.e., asRadioButtons
is false
),
the whole element specified by selector
will be replaced by a new select
element.
When asRadioButtons
is true
, the element specified by selector
will be
repeated once for each of the passed options
. The option label will be
used to set the text of the label
. If the radio button is nested in the
label
, it will be left at the end of the label
. If a given
SelectableOption
specifies an id
attribute, in addition to that
attribute being set on the radio button, the for
attribute of the label
element (if present) will be set to the same value.
This case class creates a field holder for a simple field that gets a String from the client.
A Validation that validates a value of type T.
A Validation that validates a value of type T. It should return a Box[String] that is Full with a validation error if there are validation problems, or an empty box if there are no such problems.
Validations can provide a css selector that attaches validation-related attributes to the input field.
There is an implicit conversion from a (T)=>Box[String] function to a Validation[T] that simply makes no changes to the relevant input field
Provides basic checking that a number is within a range.
Provides basic checking that a number is within a range. This can be used standalone, but it's recommended that you use it via one of its subclasses that also provides client-side annotations for the range.
The range is inclusive.
Example: myField ? basicInRange(0, 100)
Provides basic checking that a string is not empty.
Provides basic checking that a string is not empty. This can be used standalone, but it's recommended that you use it via one of its subclasses that also provides client-side annotations for the range.
Example: myField ? basicNotEmpty
Contains validations that apply HTML5 attributes to support them on the client.
Contains validations that apply parsley.js attributes to support them on the client.
Contains validations that apply parsley.js attributes to support them on the client. Validation names follow parsley.js names.
FIXME These are incomplete.
FieldHolder represents a form field that processes a value of type FieldValueType, and that can run a set of validations on the incoming field value when it is submitted. It can also attach event handler callbacks that call back to the server with the current inputted value when certain events occur on the client.
This base provides about 80% of the structure that most fields will share. It provides an overridable handler function that will handle the field when it is submitted in a form. This can be overridden by child classes for e.g. file handling.