react-hook-form-bound coordinate field. Renders the @uxf/ui/text-input primitive with type="text", parses the typed coordinate string with coordinate-parser, and stores a { lat, lng } object, managing the input's isInvalid and helperText from form state.
Use @uxf/form/gps-input for a GPS coordinate field inside a @uxf/form form when the form value must be a parsed { lat, lng } object. The user types coordinates in any of many supported formats (decimal, DMS, with/without hemisphere letters, …); the field parses them to latitude/longitude and shows the parsed result plus a "supported formats" tooltip in the helper text. There is no same-named @uxf/ui twin; for a plain text field use @uxf/ui/text-input.
import { Form } from "@uxf/form/form";
import { GpsInput, GpsInputValue } from "@uxf/form/gps-input";
import { useForm } from "react-hook-form";
interface FormData {
location: GpsInputValue | null;
}
function Example() {
const formApi = useForm<FormData>({ defaultValues: { location: null } });
return (
<Form formApi={formApi} id="example" onSubmit={(values) => console.log(values)}>
<GpsInput control={formApi.control} isRequired label="GPS" name="location" placeholder="Enter coordinates" />
</Form>
);
}
Value is Gps (GpsInputValue) — { lat: number; lng: number }. The visible input holds the raw coordinate string; on a successful parse the field value is set to the { lat, lng } object, on a failed parse it is set to null.
GpsInputProps<FormData> = ControlProps<FormData> + the visual props of the @uxf/ui/text-input twin (minus the ones this field manages: isFocused, isInvalid, max, min, name, onChange, pattern, step, value, type) + the props below.
| Prop | Type | Default | Description |
|---|---|---|---|
control |
Control<FormData> |
— | Required. The control from useForm. |
name |
FieldPath<FormData> |
— | Required. Field path in the form values. |
rules |
RegisterOptions |
— | Extra react-hook-form rules; merged with the built-in validation below. |
shouldUnregister |
boolean |
— | Unregister the field (drop its value) on unmount. |
isRequired |
boolean |
false |
Adds a required check and the required indicator. |
requiredMessage |
string |
localized | Message for the required check. |
onChange |
(value: string, event) => void |
— | Called after every keystroke with the raw input string (not the parsed { lat, lng }). |
All other props (label, placeholder, size, variant, leftAddon/rightAddon/leftElement/rightElement, maxLength, autoComplete, …) are forwarded to the twin — see @uxf/ui/text-input. Note: helperText is computed by the field (parsed value / error + tooltip) and cannot be overridden.
isRequired adds a req validator (requiredMessage to override; key uxf-form-gps-input:validation.required).format validator flags unparseable input (key uxf-form-gps-input:validation.invalid-coordinates, interpolates {{value}}).uxf-form-gps-input:validation.empty-coordinates and a tooltip labelled uxf-form-gps-input:validation.supported-formats.rules; the field-level error and format state drive the twin's helperText and isInvalid.Form — it reads the form context (formId, and inherits isDisabled / isReadOnly) and needs a react-hook-form control.@uxf/ui/text-input (and @uxf/ui/tooltip for the formats hint), so include those components' stylesheet(s) and the @uxf/ui token layer — see @uxf/ui/text-input.coordinate-parser package for parsing.@uxf/ui/text-input