enhancement
major
minor
major
minor
major
#29548
React view UI: URL, e-mail and phone attributes are edited as typed inputs and displayed as links
Affects 8.0.0-alpha8 (React view UI).
The problem
An attribute of type tl.util:URL is a plain text field in the React view UI. FieldControlService has no provider mapped to that type, so the request falls through to the fallback, TextInputControlProvider, which builds a ReactTextInputControl. On the client, TLTextInput.tsx hard-codes type="text".
The consequences for a form or a table cell holding a URL:
- In edit mode the browser gives no URL keyboard, no URL validation, and no autocompletion of previously entered addresses, because the input is not a url input.
- In view mode the value is written as text. A user who wants to open the address has to select it, copy it, and paste it into the location bar. The same holds for a URL column in a <table>.
- A value entered without a scheme (example.com) is what users type, but it is neither completed nor rejected.
An application that needs a usable URL field has to register its own ReactFieldControlProvider for tl.util:URL, write a ReactFormFieldControl subclass, and ship a second text-input React component whose only differences are the input type and a link next to it. That is a full custom control for a one-attribute change.
There are no model types for e-mail addresses and phone numbers at all, although both are the same kind of value: a text with a dedicated input type and a link (mailto:, tel:).
Lösung
Typed text input. ReactTextInputControl gets an input type (InputType: text, url, email, tel, search), passed to the client as state and rendered as the type attribute of the input in TLTextInput.tsx. Default is text, so existing fields are unchanged. One control serves all types: the typing protocol (debounce, flush on blur, submit on Enter, commit on blur, error chrome, multi-line variant) is shared, only the input attribute, the link rule and the normalization rule differ.
Link display. For url, email and tel the client derives a link target from the value (mailto: and tel: for the latter two, the phone number without its spaces). In view mode, and thus in table cells, the value is rendered as an <a href target="_blank" rel="noopener noreferrer">. In edit mode an open-link icon is shown next to the input while the value is non-empty and error-free. The single-line input always sits in the same wrapper, so that the link appearing or disappearing does not remount the input and typing keeps the focus.
Normalization on the client. A url field trims its value and prepends https:// to a scheme-less value when the field loses focus (and when Enter submits it), before the value is sent. The user sees the value that is stored; values with a scheme (including mailto:) pass through unchanged. A url field sends its value only on blur (sendValueOnBlur), so the half-typed address in between is never judged by the server. The server additionally rejects a non-empty URL value that is no absolute URI with the field error "Invalid web address", as a safety net against clients that bypass the normalization.
Configurable provider. TextInputControlProvider gets an input-type configuration property. The default FieldControlService configuration maps tl.util:URL, tl.util:EMail and tl.util:Phone to it with the matching input type; no per-type provider class is needed.
Model types. tl.util:EMail and tl.util:Phone are added next to tl.util:URL (string datatypes, created in existing databases by the kbase migration Ticket_29548_create_email_phone). The React attributes demo (tl-demo-react) gets an e-mail and a phone attribute next to its URL attribute, and its table shows the three columns.
Test
- TestReactTextInputControl (tl-layout-react): input type state, URL validation, send-on-blur.
- TestTextInputControlProvider (tl-layout-view): configured input type, shipped type mapping.
- tl-demo-react: "Attribute" → "Auswahl + Formular": URL, E-Mail-Adresse, Telefonnummer as typed inputs with open-link icon, normalization on blur, rejection of an invalid address, links in view mode and in the table columns.
Migration
The datatypes tl.util:EMail and tl.util:Phone are created in existing databases by the automatic kbase migration Ticket_29548_create_email_phone (module tl-element); no manual step is needed. An application that already defines a type named EMail or Phone in the module tl.util would collide with the framework types and must rename or drop its own definition before the update.