In a JSON schema the format
keyword has a number of pre-defined formats (date
, email
, etc.) but can also be any custom format (see 7. Semantic Validation with "format"). If you simply need a to match a field against a regular expression you should use the pattern
keyword instead. Custom formats are intended for annotation and more complex validation that is not possible to accomplish with a regex.
{ prefix : Maybe String
, suffix : Maybe String
, placeholder : Maybe String
, autocomplete : Maybe String
, inputType : Maybe String
, lines : Basics.Int
, input : Maybe (Form.Input.Input Json.Schema.Form.Error.ErrorValue String)
, validation : String -> Form.Validate.Validation Json.Schema.Form.Error.ErrorValue String
}
A custom format.
init : Format
Initialize a new format with default values.
withPrefix : String -> Format -> Format
A short label that is displayed at the beginning of the input field.
withSuffix : String -> Format -> Format
A short label that is displayed at the end of the input field.
withPlaceholder : String -> Format -> Format
A short hint that describes the expected value of the field.
withAutocompleteOff : Format -> Format
The browser is not permitted to automatically enter or select a value for this field.
withAutocompleteOn : Format -> Format
The browser is allowed to automatically complete the input. No guidance is provided as to the type of data expected in the field, so the browser may use its own judgement.
withAutocomplete : String -> Format -> Format
The browser is allowed to automatically complete the input. See https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete for a list of possible values and https://cloudfour.com/thinks/autofill-what-web-devs-should-know-but-dont/ for in-depth guidance on how to use autocomplete.
withInputType : String -> Format -> Format
The type of input
to use. The default is text
.
withLines : Basics.Int -> Format -> Format
The expected number of lines. If more than one the field will be rendered as a textarea
. The default is 1.
withInput : Form.Input.Input Json.Schema.Form.Error.ErrorValue String -> Format -> Format
Customize the input field with your own HTML.
withValidation : (String -> Form.Validate.Validation Json.Schema.Form.Error.ErrorValue String) -> Format -> Format
A validation function (see etaque/elm-form for details on how to write a validation function).