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

Cannot define DVR rules as array as per validatorjs docs only pipe delimited string #137

Closed itaylorweb closed 8 years ago

itaylorweb commented 8 years ago

ValidatorJS allows DVR rules to be defined as an array and not just pipe delimited string. When defining regex validation its recommend to define as an array such as: ['required', 'regex:/^(19|20)[\d]{2,2}$/'] as the pipe in the regex pattern would cause a problem when splitting if it was pipe delimited.

DVR.js

Change:

{
    key: 'rules',
    value: function rules(_rules, type) {
      var diff = [];
      var $rules = (0, _split3.default)(_rules, '|');
      if (type === 'sync') diff = (0, _difference3.default)($rules, this.asyncRules);
      if (type === 'async') diff = (0, _intersection3.default)($rules, this.asyncRules);
      return diff;
    }
  }

To:

{
    key: 'rules',
    value: function rules(_rules, type) {
      var diff = [];
      var $rules = [];
      if (typeof _rules === 'string') {
        $rules = (0, _split3.default)(_rules, '|');
      } else {
        $rules = _rules;
      }
      // var $rules = (0, _split3.default)(_rules, '|');
      if (type === 'sync') diff = (0, _difference3.default)($rules, this.asyncRules);
      if (type === 'async') diff = (0, _intersection3.default)($rules, this.asyncRules);
      return diff;
    }
  }
foxhound87 commented 8 years ago

@itaylorweb you can clone the repo and edit the original source code instead of modify the transpiled code. Then you can contribute also with pull requests if you want.

itaylorweb commented 8 years ago

Sorry. I should've done that. Will do next time :)