How to use the final-form.getIn function in final-form

To help you get started, we’ve selected a few 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 airbnb / lunar / packages / forms / src / components / Form / index.tsx View on Github external
setFieldConfig(
    [name, config]: [string, Field<unknown>],
    { fields, formState }: MutableState<object>,
  ) {
    const field = fields[name];
    const initial = getIn(formState.initialValues!, name);
    const value = typeof initial === 'undefined' ? config.defaultValue : initial;

    if (!field) {
      return;
    }

    field.data.config = config;
    // @ts-ignore
    field.initial = value;
    // @ts-ignore
    field.value = value;
    field.touched = config.validateDefaultValue || false;

    // These are needed for form "reset" to work correctly!
    /* eslint-disable no-param-reassign */
    formState.initialValues = setIn(formState.initialValues!, name, value);
github final-form / final-form-calculate / src / decorator.js View on Github external
const runUpdates = (
          field: string,
          isEqual: (any, any) => boolean,
          updates: Updates
        ) => {
          const next = values && getIn(values, field)
          const previous = previousValues && getIn(previousValues, field)
          if (!isEqual(next, previous)) {
            if (typeof updates === 'function') {
              const results = updates(next, field, values, previousValues)
              if (isPromise(results)) {
                results.then(resolved => {
                  Object.keys(resolved).forEach(destField => {
                    form.change(destField, resolved[destField])
                  })
                })
              } else {
                Object.keys(results).forEach(destField => {
                  form.change(destField, results[destField])
                })
              }
            } else {
github kalmhq / kalm / frontend / src / tutorials / utils.ts View on Github external
return errors;
  }

  const currentStep = tutorial.steps[state.currentStepIndex];
  if (!currentStep) {
    return errors;
  }

  for (let i = 0; i < currentStep.subSteps.length; i++) {
    const subStep = currentStep.subSteps[i];

    if (subStep.formValidator) {
      for (let j = 0; j < subStep.formValidator.length; j++) {
        const rule = subStep.formValidator[j];
        if (rule.form === form) {
          const error = rule.validate(getIn(values, rule.field));

          if (error) {
            errors[rule.field] = error;
          }
        }
      }
    }
  }

  return errors;
};
github final-form / final-form-calculate / src / decorator.js View on Github external
const runUpdates = (
          field: string,
          isEqual: (any, any) => boolean,
          updates: Updates
        ) => {
          const next = values && getIn(values, field)
          const previous = previousValues && getIn(previousValues, field)
          if (!isEqual(next, previous)) {
            if (typeof updates === 'function') {
              const results = updates(next, field, values, previousValues)
              if (isPromise(results)) {
                results.then(resolved => {
                  Object.keys(resolved).forEach(destField => {
                    form.change(destField, resolved[destField])
                  })
                })
              } else {
                Object.keys(results).forEach(destField => {
                  form.change(destField, results[destField])
                })
              }
            } else {
              Object.keys(updates).forEach(destField => {
github kalmhq / kalm / frontend / src / tutorials / utils.ts View on Github external
export const isFormFieldValueEqualTo = (rootState: RootState, form: string, field: string, value: any) => {
  const formValuesMap = rootState.tutorial.formValues;
  const formValues = formValuesMap ? formValuesMap[form] : undefined;

  if (!formValues) {
    return false;
  }
  return Array.isArray(getIn(formValues, field))
    ? getIn(formValues, field)[0] === value[0]
    : getIn(formValues, field) === value;
};
github airbnb / lunar / packages / forms / src / components / Form / index.tsx View on Github external
fields.map(async field => {
        if (!field) return;

        const { name, data: fieldData } = field;

        if (fieldData && fieldData.config && fieldData.config.validator) {
          const value = getIn(data, name);

          if (typeof value !== 'undefined') {
            try {
              await fieldData.config.validator(value, data);
            } catch (error) {
              errors = setIn(errors, name, error.message);
            }
          }
        }
      }),
    );
github kalmhq / kalm / frontend / src / tutorials / utils.ts View on Github external
export const isFormFieldValueEqualTo = (rootState: RootState, form: string, field: string, value: any) => {
  const formValuesMap = rootState.tutorial.formValues;
  const formValues = formValuesMap ? formValuesMap[form] : undefined;

  if (!formValues) {
    return false;
  }
  return Array.isArray(getIn(formValues, field))
    ? getIn(formValues, field)[0] === value[0]
    : getIn(formValues, field) === value;
};