Skip to main content
Light Dark System

Input Widget

Et2InputWidget Mixin / Controller

Used by

This mixin is applied by the following widgets.

Properties

Name Description Type Default
autofocus Have browser focus this input on load. Overrides etemplate2.focusOnFirstInput(), use only once per page https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attributes boolean -
hasFeedbackFor Get a list of feedback types string[] -
translate List of properties that get translated Done separately to not interfere with properties - if we re-define label property, labels go missing. - -
needed Compatibility for deprecated name “needed”
use required instead
- -

Methods

Name Description Arguments
et2HandleBlur() If the value is unchanged, put any held validation messages back Named et2HandleBlur to avoid overwriting handleBlur() in Shoelace components _ev: FocusEvent
et2HandleFocus() When input receives focus, clear any validation errors. If the value is the same on blur, we’ll put them back The ones from the server (ManualMessage) can interfere with submitting. Named et2HandleFocus to avoid overwriting handleFocus() in Shoelace components _ev: FocusEvent
getInputNode() Get input to e.g. set aria-attributes -
handleSlChange() Handle sl-change event from Shoelace components and dispatch a change event so anything listening for change events can react to it instead of having to listen for both sl-change and change. event:
isValid() Used by etemplate2 to determine if we can submit or not messages:
submit() Called whenever the template gets submitted. We return false if the widget is not valid, which cancels the submission. _values:
validate() Massively simplified validate, as compared to what ValidatorMixin gives us, since ValidatorMixin extends FormControlMixin which breaks SlSelect’s render() We take all validators for the widget, and if there’s a value (or field is required) we check the value with each validator. For array values we check each element with each validator. If the value does not pass the validator, we collect the message and display feedback to the user. We handle validation errors from the server with ManualMessages, which always “fail”. If the value is empty, we only validate if the field is required. skipManual:
_oldChange() Change handler calling custom handler set via onchange attribute _ev: Event