How to use the formik.useField function in formik

To help you get started, we’ve selected a few formik 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 Mines-Paristech-Students / Portail-des-eleves / frontend / src / components / utils / forms / SelectUsers.tsx View on Github external
export const SelectUsers = ({
    isMulti = true,
    className = "",
    ...props
}: {
    isMulti?: boolean;
    name: string;
    className?: string;
    [key: string]: any;
}) => {
    const [, meta, helpers] = useField(props);
    const { value } = meta;
    const { setValue } = helpers;

    const { data } = useBetterQuery>(
        ["listUsers", {}, 1],
        api.users.list,
        {
            refetchOnWindowFocus: false,
        }
    );

    // react-select requires an `options` field of a special type. These hooks handle this.
    const [usersOptions, setUsersOptions] = useState<
        OptionsType<{ value: string; label: string }>
    >([]);
github Mines-Paristech-Students / Portail-des-eleves / frontend / src / pages / courses / evaluations / Evaluate.tsx View on Github external
export const RatingField = ({ question, label, ...props }) => {
    // @ts-ignore
    const [field, meta, helpers] = useField(props);

    const setValue = (value) => {
        field.value[question.id] = value;
        helpers.setValue(field.value);
    };

    if (meta.touched &amp;&amp; meta.error) return <p>{meta.error}</p>
    return (
        
            {Array.from(Array(5).keys()).map((index) =&gt;
                <button style="{{"> setValue(index + 1)}
                &gt;
                    {(index &lt; field.value[question.id])</button>
github Mines-Paristech-Students / Portail-des-eleves / frontend / src / pages / associations / elections / ActiveList.tsx View on Github external
const ChoicesField = (props) =&gt; {
    const [field, meta, helpers] = useField(props);

    const handleClick = (choice: Choice) =&gt; {

        const index = field.value.findIndex((e)=&gt;e===choice.id);
        const newSelected: number[] = field.value.slice();
        if (index &gt;= 0) {
            newSelected.splice(index, 1)
        } else {
            newSelected.push(choice.id)
        }
        if (newSelected.length &gt; props.maxChoicesPerBallot) {
            newSelected.shift()
        }
        helpers.setValue(newSelected)
    };
github Mines-Paristech-Students / Portail-des-eleves / frontend / src / pages / associations / elections / Edit.tsx View on Github external
const DatesField = (props) =&gt; {
    const [field, meta] = useField(props)
    return (
        
            <h4>Dates</h4>
github vanilla / vanilla / library / src / scripts / forms / themeEditor / ThemePresetDropDown.tsx View on Github external
data: {
                fg: color("#fff"),
                bg: color("#555a62"),
            },
        },
    ];

    let defaultValue = options[0];

    const [currentOption, setCurrentOption] = useState(defaultValue);

    const fgID = "global.mainColors.fg";
    const bgID = "global.mainColors.bg";

    const [fgValue, fgValueMeta, fgValueHelpers] = useField(fgID);
    const [bgValue, bgValueMeta, bgValueHelpers] = useField(bgID);

    const onChange = (option: IComboBoxOption | undefined) =&gt; {
        if (option) {
            fgValueHelpers.setTouched(true);
            bgValueHelpers.setTouched(true);
            fgValueHelpers.setValue(option.data.fg.toHexString());
            bgValueHelpers.setValue(option.data.bg.toHexString());
            setCurrentOption(option as any);
        }
    };

    const inputID = useUniqueID("themePreset");
    const labelID = useUniqueID("themePresetLabel");

    return (
github openshift / console / frontend / packages / console-shared / src / components / formik-fields / DroppableFileInputField.tsx View on Github external
const DroppableFileInputField: React.FC = ({ name, label, helpText }) =&gt; {
  const [field] = useField(name);
  const { setFieldValue } = useFormikContext();
  const fieldId = getFieldId(name, 'droppable-input');
  return (
    
       setFieldValue(name, fileData)}
        inputFileData={field.value}
        inputFieldHelpText={helpText}
        aria-describedby={`${fieldId}-helper`}
      /&gt;
    
  );
};
github openshift / console / frontend / packages / dev-console / src / components / import / git / SourceSecretSelector.tsx View on Github external
const SourceSecretSelector: React.FC = () =&gt; {
  const [secret] = useField('git.secret');
  const { values, setFieldValue } = useFormikContext();

  const handleSave = (name: string) =&gt; {
    setFieldValue('git.secret', name);
  };

  const handleDropdownChange = (key: string) =&gt; {
    if (key === CREATE_SOURCE_SECRET) {
      setFieldValue('git.secret', secret.value);
      secretModalLauncher({
        namespace: values.project.name,
        save: handleSave,
        secretType: SecretTypeAbstraction.source,
      });
    } else {
      setFieldValue('git.secret', key);
github openshift / console / frontend / packages / console-shared / src / components / formik-fields / ToggleableFieldBase.tsx View on Github external
const ToggleableFieldBase: React.FC = ({
  label,
  formLabel,
  helpText,
  required,
  children,
  ...props
}) =&gt; {
  const [field, { touched, error }] = useField(props.name);
  const fieldId = getFieldId(props.name, 'checkbox');
  const isValid = !(touched &amp;&amp; error);
  const errorMessage = !isValid ? error : '';
  return (
    
      {children({
        ...field,
        ...props,
        id: fieldId,
github ZupIT / horusec-platform / manager / src / components / Calendar / index.tsx View on Github external
function CalendarMui({
  name,
  label,
  disabled = false,
  minDate,
  maxDate,
}: CalendarProps) {
  const { i18n } = useTranslation();
  const [locale, setLocale] = useState('enUS');
  const [dateFormat, setDateFormat] = useState('dd/MM/yyyy');
  const { allLanguages } = useLanguage();

  const [field, { error, touched, value }] = useField(name);

  useEffect(() =&gt; {
    const lang = find(allLanguages, { i18nValue: i18n.language });
    setDateFormat(lang.dateFormat);
    setLocale(lang.i18nValue as LocaleType);
  }, [i18n.language, allLanguages]);

  return (
github palmerhq / radio-group / example / index.js View on Github external
function FRadioGroup(props) {
  const [{ onChange, onBlur, ...field }] = useField(props.name);
  return (
    
  );
}