How to use the @commercetools-frontend/ui-kit.TextInput.isEmpty 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
const validate = (formValues, locale) => {
  // To make it easier to attach errors during validation, we initialize
  // all form fields to empty objects.
  const errors = {
    key: {},
    name: {},
    slug: {},
    description: {},
    inventory: {},
    price: {},
  };

  // validate key
  // Input elements usually provide a way to check whether it's value is empty
  // This is useful to determine whether a required value was not filled out.
  if (TextInput.isEmpty(formValues.key)) errors.key.missing = true;

  // validate name
  // A localized string is considered empty when no translation is given at all
  if (LocalizedTextInput.isEmpty(formValues.name)) errors.name.missing = true;

  // validate slug
  // A slug must match [a-zA-Z0-9_-]{2,256}
  // The error object of the slug is
  //  {
  //    missing: Boolean,
  //    translations: { de: { hasForbiddenChars: Boolean }, ... },
  //  }
  // The "missing" part is used to highlight all fields, while the
  // "translations" part gets mapped to errors per translation.
  if (LocalizedTextInput.isEmpty(formValues.slug)) {
    errors.slug.missing = true;
github commercetools / ui-kit / examples / form-fields.example.story.js View on Github external
const validate = (formValues, locale) => {
  // To make it easier to attach errors during validation, we initialize
  // all form fields to empty objects.
  const errors = {
    key: {},
    description: {},
    inventory: {},
    price: {},
  };

  // validate key
  // Input elements usually provide a way to check whether it's value is empty
  // This is useful to determine whether a required value was not filled out.
  if (TextInput.isEmpty(formValues.key)) errors.key.missing = true;

  // validate description
  if (MultilineTextInput.isEmpty(formValues.description))
    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
github commercetools / merchant-center-application-kit / packages / application-shell / src / components / login / validations.js View on Github external
export const validate = values => {
  const errorsByField = {
    email: {},
    password: {},
  };

  if (TextInput.isEmpty(values.email)) {
    errorsByField.email.missing = true;
  } else if (!emailRegex.test(values.email)) {
    errorsByField.email.invalid = true;
  }
  if (TextInput.isEmpty(values.password)) errorsByField.password.missing = true;

  return omitEmpty(errorsByField);
};
github commercetools / merchant-center-application-kit / packages / application-shell / src / components / login / validations.js View on Github external
export const validate = values => {
  const errorsByField = {
    email: {},
    password: {},
  };

  if (TextInput.isEmpty(values.email)) {
    errorsByField.email.missing = true;
  } else if (!emailRegex.test(values.email)) {
    errorsByField.email.invalid = true;
  }
  if (TextInput.isEmpty(values.password)) errorsByField.password.missing = true;

  return omitEmpty(errorsByField);
};
github commercetools / merchant-center-application-kit / packages / application-components / src / components / modal-pages / custom-form-modal-page / custom-form-modal-page.example.js View on Github external
validate={formikValues => {
                  if (TextInput.isEmpty(formikValues.email)) {
                    return { email: { missing: true } };
                  }
                  return {};
                }}
                onSubmit={formikValues => {
github commercetools / merchant-center-application-kit / packages / application-components / src / components / dialogs / form-dialog / form-dialog.story.js View on Github external
validate={formikValues => {
              if (TextInput.isEmpty(formikValues.email)) {
                return { email: { missing: true } };
              }
              return {};
            }}
            onSubmit={formikValues => {
github commercetools / merchant-center-application-kit / packages / application-shell / src / components / login-sso / validations.js View on Github external
export const validate = values => {
  const errorsByField = {
    organizationName: {},
  };

  if (TextInput.isEmpty(values.organizationName)) {
    errorsByField.organizationName.missing = true;
  }

  return omitEmpty(errorsByField);
};