foxhound87 / mobx-react-form

Reactive MobX Form State Management
https://foxhound87.github.io/mobx-react-form
MIT License
1.1k stars 129 forks source link

localization and required option using ajv (svk) #537

Closed rideddy84 closed 2 years ago

rideddy84 commented 4 years ago

I use below plugins options.

import svk from 'mobx-react-form/lib/validators/SVK';
import ajv from 'ajv';

const plugins = (schema): svk => ({
  svk: svk({
    package: ajv,
    schema,
    options: {
      errorDataPath: 'property',
      allErrors: true,
      coerceTypes: true,
      v5: true,
    }, // ajv options
  }),
});

export default plugins;

I am happy with this module in general, but I have two problems.

  1. Localization The ajv has lots of sub packages like ajv-i18n. But I can't find the way to enable them in mobx-react-form.

  2. I can't enable required message.

    const $schema = {
    type: 'object',
    properties: {
    id: {
      type: 'string', minLength: 5, maxLength: 20,
    },
    password: { type: 'string', minLength: 6, maxLength: 20 },
    username: { type: 'string', minLength: 6, maxLength: 20 },
    },
    required: ['id', 'password', 'username'],
    };

    This is my schema. But only minLength error messages appear.

Thanks.