Class: Toggle

Field that has two states, either on or off.

Falseness is represented by an absent value or an empty string; truth is represented by anything else. A typical visual representation for this field is a single checkbox.

Toggles are different from other fields in that an absence of value is a meaningful state (i.e. falseness). The concept of requiredness is therefore not well-defined for them. They also may never fail validation.

Methods

has_value (self, input)

Return whether a value has been provided for the field in the given MultiDict of input.

This is another unintuitive method. While translate() always returns a non-null value, it is indeed possible (and likely) for no value to be provided as input, which evaluates to falseness.

required (self)

Return True, as it is impossible to omit a value.

translate (self, input)

Translate the field from a MultiDict of values.