How to use the react-final-form.useField function in react-final-form

To help you get started, we’ve selected a few react-final-form examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ewels / MegaQC / src / admin / components / resourceLink.js View on Github external
export default function ResourceLink({ reference, source, dest, children }) {
  // const form = useForm();
  // const localValue = form.getFieldState(source);
  const localValue = useField(source);
  const query = encodeURIComponent(
    JSON.stringify({
      [dest]: localValue.input.value
    })
  );
  const title = titleize(reference);
  return (
    <button label="{`Add">
      {children}</button>
github final-form / react-final-form / examples / chakra / index.js View on Github external
const CheckboxArrayControl = ({ name, value, children }) =&gt; {
  const {
    input: { checked, ...input },
    meta: { error, touched }
  } = useField(name, {
    type: 'checkbox', // important for RFF to manage the checked prop
    value // important for RFF to manage list of strings
  })
  return (
    
      {children}
    
  )
}
github urbit / bridge / src / indigo-react / components / ToggleInput.js View on Github external
// visuals
  name,
  label,
  inverseLabel,
  inverseColor = 'black',
  className,

  //
  disabled = false,

  ...rest
}) {
  const {
    input,
    meta: { submitting, submitSucceeded },
  } = useField(name, { type: 'checkbox' });

  disabled = disabled || submitting || submitSucceeded;

  return (
    
      {/* we totally hide the checkbox itself */}
github marmelab / react-admin / packages / ra-core / src / form / useInput.ts View on Github external
id,
    name,
    source,
    validate,
    onBlur: customOnBlur,
    onChange: customOnChange,
    onFocus: customOnFocus,
    ...options
}: InputProps): ComputedInputProps => {
    const finalName = name || source;

    const sanitizedValidate = Array.isArray(validate)
        ? composeValidators(validate)
        : validate;

    const { input, meta } = useFinalFormField(finalName, {
        initialValue: defaultValue,
        validate: sanitizedValidate,
        ...options,
    });

    // Extract the event handlers so that we can provide ours
    // allowing users to provide theirs without breaking the form
    const { onBlur, onChange, onFocus, ...inputProps } = input;

    const handleBlur = useCallback(
        event => {
            onBlur(event);

            if (typeof customOnBlur === 'function') {
                customOnBlur(event);
            }
github urbit / bridge / src / indigo-react / components / SelectInput.js View on Github external
export default function SelectInput({
  name,
  label,
  placeholder,
  className,
  mono = false,
  options = [],
  disabled = false,
  warning,
}) {
  const {
    input,
    meta: { active, error, submitting, submitSucceeded, touched, valid },
  } = useField(name, {
    type: 'select',
  });

  disabled = disabled || submitting || submitSucceeded;

  const [isOpen, setIsOpen] = useState(false);
  const ref = useRef();

  // close select on outside clicks
  useOnClickOutside(ref, useCallback(() => setIsOpen(false), [setIsOpen]));

  const toggleOpen = useCallback(() => {
    input.onFocus();
    setIsOpen(isOpen => !isOpen);
  }, [input]);
github marmelab / react-admin / packages / ra-ui-materialui / src / input / RadioButtonGroupInputItem.tsx View on Github external
choice,
    optionText,
    optionValue,
    source,
    translateChoice,
}) =&gt; {
    const { getChoiceText, getChoiceValue } = useChoices({
        optionText,
        optionValue,
        translateChoice,
    });
    const label = getChoiceText(choice);
    const value = getChoiceValue(choice);
    const {
        input: { type, onChange, ...inputProps },
    } = useField(source, {
        type: 'radio',
        value,
    });

    const nodeId = `${source}_${label}`;

    return (
         onChange(value)}
                    {...inputProps}
github urbit / bridge / src / form / UploadInput.js View on Github external
export default function UploadInput({ name, label, ...rest }) {
  const {
    input,
    meta: { validating, submitting, touched, active, error },
  } = useField(name, { type: 'text' });

  const handleUpload = useCallback(
    element => {
      input.onFocus();

      const file = element.files.item(0);
      const reader = new FileReader();

      reader.onload = e => {
        input.onChange({ target: { value: e.target.result } });
      };

      const failure = _ => {
        input.onBlur();
      };
github coralproject / talk / src / core / client / admin / routes / Configure / sections / WebhookEndpoints / ConfigureWebhookEndpointForm / EventsSelectField.tsx View on Github external
const EventsSelectField: FunctionComponent = ({ settings }) =&gt; {
  const { input: all } = useField("all");
  const { input: events, meta } = useField("events", {
    validate: validateEventSelection,
  });

  const onClear = useCallback(() =&gt; {
    if (all.value) {
      all.onChange(false);
    } else {
      events.onChange([]);
    }
  }, [all, events]);

  const onCheckChange = useCallback(
    (event: WEBHOOK_EVENT_NAME, selectedIndex: number) =&gt; () =&gt; {
      const changed = [...events.value];
      if (selectedIndex &gt;= 0) {
github urbit / bridge / src / form / Inputs.js View on Github external
export function PointInput({ name, size = 4, ...rest }) {
  const {
    input: { value },
    meta: { active, valid, error },
  } = useField(name, {
    subscription: { value: true, active: true, valid: true, error: true },
  });

  return (
github urbit / bridge / src / form / EmailChipInput.js View on Github external
const Chip = ({ onDelete, disabled, name }) =&gt; {
  const { input } = useField(name, { subscription: { value: true } });
  return (
    
      {input.value}
      
        ✗
      
    
  );
};

react-final-form

🏁 High performance subscription-based form state management for React

MIT
Latest version published 3 years ago

Package Health Score

70 / 100
Full package analysis

Similar packages