How to use the @commercetools-frontend/ui-kit.MoneyInput.isHighPrecision function in @commercetools-frontend/ui-kit

To help you get started, we’ve selected a few @commercetools-frontend/ui-kit 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 commercetools / ui-kit / examples / form-inputs.example.story.js View on Github external
errors.description.missing = true;

  // validate inventory
  if (NumberInput.isEmpty(formValues.inventory)) {
    errors.inventory.missing = true;
  } else {
    // When the value is not empty, we can assume that it is a number
    if (formValues.inventory < 0) errors.inventory.negative = true;
    if (NumberInput.hasFractionDigits(formValues.inventory))
      errors.inventory.fractions = true;
  }

  // validate price
  if (MoneyInput.isEmpty(formValues.price)) {
    errors.price.missing = true;
  } else if (MoneyInput.isHighPrecision(formValues.price, locale)) {
    errors.price.unsupportedHighPrecision = true;
  }

  // Formik will think there are errors when the object returned as a
  // validation result has at least one key. We therefore have to omit
  // all empty fields inside the error object.
  // When an empty object is returned, formik will assume there were no errors
  return omitEmpty(errors);
};
github commercetools / ui-kit / examples / form-fields.example.story.js View on Github external
errors.description.missing = true;

  // validate inventory
  if (NumberInput.isEmpty(formValues.inventory)) {
    errors.inventory.missing = true;
  } else {
    // When the value is not empty, we can assume that it is a number
    if (formValues.inventory < 0) errors.inventory.negative = true;
    if (NumberInput.hasFractionDigits(formValues.inventory))
      errors.inventory.fractions = true;
  }

  // validate price
  if (MoneyInput.isEmpty(formValues.price)) {
    errors.price.missing = true;
  } else if (MoneyInput.isHighPrecision(formValues.price, locale)) {
    errors.price.unsupportedHighPrecision = true;
  }

  // Formik will think there are errors when the object returned as a
  // validation result has at least one key. We therefore have to omit
  // all empty fields inside the error object.
  // When an empty object is returned, formik will assume there were no errors
  return omitEmpty(errors);
};