iglooform 2.5.26 → 2.5.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,7 +10,7 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
10
10
  import { jsx as _jsx } from "react/jsx-runtime";
11
11
  import omit from 'omit.js';
12
12
  import formMethods from '../utils/form-methods';
13
- import { staticFormatMessage } from '../locale';
13
+ import { staticFormatMessage as formatMessage } from '../locale';
14
14
  import './style/index.less';
15
15
 
16
16
  var IglooInputNumber = function IglooInputNumber(props) {
@@ -44,14 +44,14 @@ IglooInputNumber.formItemPropsHandler = function (config) {
44
44
  maxLength = config.maxLength,
45
45
  minLength = config.minLength,
46
46
  label = config.label,
47
- idType = config.idType;
47
+ pattern = config.pattern;
48
48
  var rules = [];
49
49
 
50
50
  if (length !== undefined) {
51
51
  rules.push({
52
52
  validator: function validator(_, value) {
53
53
  if (value === undefined || value === null || String(value).length === length) return Promise.resolve();
54
- return Promise.reject(staticFormatMessage({
54
+ return Promise.reject(formatMessage({
55
55
  id: '{label} must be {length} digits.',
56
56
  values: {
57
57
  length: length,
@@ -66,7 +66,7 @@ IglooInputNumber.formItemPropsHandler = function (config) {
66
66
  rules.push({
67
67
  validator: function validator(_, value) {
68
68
  if (value === undefined || value === null || String(value).length >= minLength && String(value).length <= maxLength) return Promise.resolve();
69
- return Promise.reject(staticFormatMessage({
69
+ return Promise.reject(formatMessage({
70
70
  id: '{label} must be {minLength} - {maxLength} digits.',
71
71
  values: {
72
72
  maxLength: maxLength,
@@ -82,7 +82,7 @@ IglooInputNumber.formItemPropsHandler = function (config) {
82
82
  rules.push({
83
83
  validator: function validator(_, value) {
84
84
  if (value === undefined || value === null || String(value).length <= maxLength) return Promise.resolve();
85
- return Promise.reject(staticFormatMessage({
85
+ return Promise.reject(formatMessage({
86
86
  id: '{label} must be less than {maxLength} digits.',
87
87
  values: {
88
88
  maxLength: maxLength,
@@ -97,7 +97,7 @@ IglooInputNumber.formItemPropsHandler = function (config) {
97
97
  rules.push({
98
98
  validator: function validator(_, value) {
99
99
  if (value === undefined || value === null || String(value).length >= minLength) return Promise.resolve();
100
- return Promise.reject(staticFormatMessage({
100
+ return Promise.reject(formatMessage({
101
101
  id: '{label} must be at least {minLength} digits.',
102
102
  values: {
103
103
  minLength: minLength,
@@ -108,6 +108,21 @@ IglooInputNumber.formItemPropsHandler = function (config) {
108
108
  });
109
109
  }
110
110
 
111
+ if (pattern) {
112
+ rules.push({
113
+ validator: function validator(_, value) {
114
+ if (value === undefined || value === null || new RegExp(pattern).test(value)) return Promise.resolve();
115
+ return Promise.reject(formatMessage({
116
+ id: '{label} must match the pattern {pattern}.',
117
+ values: {
118
+ pattern: pattern,
119
+ label: label
120
+ }
121
+ }));
122
+ }
123
+ });
124
+ }
125
+
111
126
  return {
112
127
  getValueFromEvent: function getValueFromEvent(e) {
113
128
  var value = e.target.value;
package/es/input/input.js CHANGED
@@ -11,7 +11,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
11
11
  import { forwardRef } from 'react';
12
12
  import formMethods from '../utils/form-methods';
13
13
  import omit from 'omit.js';
14
- import { staticFormatMessage } from '../locale';
14
+ import { staticFormatMessage as formatMessage } from '../locale';
15
15
  import './style/index.less';
16
16
  var IglooInput = /*#__PURE__*/forwardRef(function (props, ref) {
17
17
  return _jsx(_Input, _objectSpread(_objectSpread({
@@ -31,8 +31,8 @@ IglooInput.formItemPropsHandler = function (config) {
31
31
  if (maxLength !== undefined && minLength !== undefined) {
32
32
  rules.push({
33
33
  validator: function validator(_, value) {
34
- if (value === undefined || value === null || String(value).length >= minLength && String(value).length <= maxLength) return Promise.resolve();
35
- return Promise.reject(staticFormatMessage({
34
+ if (value === undefined || value === null || value === '' || String(value).length >= minLength && String(value).length <= maxLength) return Promise.resolve();
35
+ return Promise.reject(formatMessage({
36
36
  id: '{label} must be {minLength} - {maxLength} characters.',
37
37
  values: {
38
38
  maxLength: maxLength,
@@ -47,8 +47,8 @@ IglooInput.formItemPropsHandler = function (config) {
47
47
  if (maxLength !== undefined && minLength === undefined) {
48
48
  rules.push({
49
49
  validator: function validator(_, value) {
50
- if (value === undefined || value === null || String(value).length <= maxLength) return Promise.resolve();
51
- return Promise.reject(staticFormatMessage({
50
+ if (value === undefined || value === null || value === '' || String(value).length <= maxLength) return Promise.resolve();
51
+ return Promise.reject(formatMessage({
52
52
  id: '{label} must be less than {maxLength} characters.',
53
53
  values: {
54
54
  maxLength: maxLength,
@@ -62,8 +62,8 @@ IglooInput.formItemPropsHandler = function (config) {
62
62
  if (maxLength === undefined && minLength !== undefined) {
63
63
  rules.push({
64
64
  validator: function validator(_, value) {
65
- if (value === undefined || value === null || String(value).length >= minLength) return Promise.resolve();
66
- return Promise.reject(staticFormatMessage({
65
+ if (value === undefined || value === null || value === '' || String(value).length >= minLength) return Promise.resolve();
66
+ return Promise.reject(formatMessage({
67
67
  id: '{label} must be at least {minLength} characters.',
68
68
  values: {
69
69
  minLength: minLength,
@@ -77,8 +77,8 @@ IglooInput.formItemPropsHandler = function (config) {
77
77
  if (pattern) {
78
78
  rules.push({
79
79
  validator: function validator(_, value) {
80
- if (new RegExp(pattern).test(value)) return Promise.resolve();
81
- return Promise.reject(staticFormatMessage({
80
+ if (value === undefined || value === null || value === '' || new RegExp(pattern).test(value)) return Promise.resolve();
81
+ return Promise.reject(formatMessage({
82
82
  id: '{label} must match the pattern {pattern}.',
83
83
  values: {
84
84
  pattern: pattern,
@@ -92,7 +92,8 @@ PhoneNumber.formItemPropsHandler = function (_ref2) {
92
92
  length = _ref2.length,
93
93
  maxLength = _ref2.maxLength,
94
94
  minLength = _ref2.minLength,
95
- label = _ref2.label;
95
+ label = _ref2.label,
96
+ pattern = _ref2.pattern;
96
97
  var rules = [{
97
98
  validator: function validator(rule, value) {
98
99
  if (!value) return Promise.resolve();
@@ -165,6 +166,21 @@ PhoneNumber.formItemPropsHandler = function (_ref2) {
165
166
  });
166
167
  }
167
168
 
169
+ if (pattern) {
170
+ rules.push({
171
+ validator: function validator(_, value) {
172
+ if (value === undefined || value === null || new RegExp(pattern).test(value.phoneNumber)) return Promise.resolve();
173
+ return Promise.reject(formatMessage({
174
+ id: '{label} must match the pattern {pattern}.',
175
+ values: {
176
+ pattern: pattern,
177
+ label: label
178
+ }
179
+ }));
180
+ }
181
+ });
182
+ }
183
+
168
184
  return {
169
185
  initialValue: phoneNumber ? {
170
186
  areaCode: Array.isArray(areaCode) ? areaCode[0] : areaCode,
@@ -58,7 +58,7 @@ IglooInputNumber.formItemPropsHandler = function (config) {
58
58
  maxLength = config.maxLength,
59
59
  minLength = config.minLength,
60
60
  label = config.label,
61
- idType = config.idType;
61
+ pattern = config.pattern;
62
62
  var rules = [];
63
63
 
64
64
  if (length !== undefined) {
@@ -122,6 +122,21 @@ IglooInputNumber.formItemPropsHandler = function (config) {
122
122
  });
123
123
  }
124
124
 
125
+ if (pattern) {
126
+ rules.push({
127
+ validator: function validator(_, value) {
128
+ if (value === undefined || value === null || new RegExp(pattern).test(value)) return Promise.resolve();
129
+ return Promise.reject((0, _locale.staticFormatMessage)({
130
+ id: '{label} must match the pattern {pattern}.',
131
+ values: {
132
+ pattern: pattern,
133
+ label: label
134
+ }
135
+ }));
136
+ }
137
+ });
138
+ }
139
+
125
140
  return {
126
141
  getValueFromEvent: function getValueFromEvent(e) {
127
142
  var value = e.target.value;
@@ -47,7 +47,7 @@ IglooInput.formItemPropsHandler = function (config) {
47
47
  if (maxLength !== undefined && minLength !== undefined) {
48
48
  rules.push({
49
49
  validator: function validator(_, value) {
50
- if (value === undefined || value === null || String(value).length >= minLength && String(value).length <= maxLength) return Promise.resolve();
50
+ if (value === undefined || value === null || value === '' || String(value).length >= minLength && String(value).length <= maxLength) return Promise.resolve();
51
51
  return Promise.reject((0, _locale.staticFormatMessage)({
52
52
  id: '{label} must be {minLength} - {maxLength} characters.',
53
53
  values: {
@@ -63,7 +63,7 @@ IglooInput.formItemPropsHandler = function (config) {
63
63
  if (maxLength !== undefined && minLength === undefined) {
64
64
  rules.push({
65
65
  validator: function validator(_, value) {
66
- if (value === undefined || value === null || String(value).length <= maxLength) return Promise.resolve();
66
+ if (value === undefined || value === null || value === '' || String(value).length <= maxLength) return Promise.resolve();
67
67
  return Promise.reject((0, _locale.staticFormatMessage)({
68
68
  id: '{label} must be less than {maxLength} characters.',
69
69
  values: {
@@ -78,7 +78,7 @@ IglooInput.formItemPropsHandler = function (config) {
78
78
  if (maxLength === undefined && minLength !== undefined) {
79
79
  rules.push({
80
80
  validator: function validator(_, value) {
81
- if (value === undefined || value === null || String(value).length >= minLength) return Promise.resolve();
81
+ if (value === undefined || value === null || value === '' || String(value).length >= minLength) return Promise.resolve();
82
82
  return Promise.reject((0, _locale.staticFormatMessage)({
83
83
  id: '{label} must be at least {minLength} characters.',
84
84
  values: {
@@ -93,7 +93,7 @@ IglooInput.formItemPropsHandler = function (config) {
93
93
  if (pattern) {
94
94
  rules.push({
95
95
  validator: function validator(_, value) {
96
- if (new RegExp(pattern).test(value)) return Promise.resolve();
96
+ if (value === undefined || value === null || value === '' || new RegExp(pattern).test(value)) return Promise.resolve();
97
97
  return Promise.reject((0, _locale.staticFormatMessage)({
98
98
  id: '{label} must match the pattern {pattern}.',
99
99
  values: {
@@ -108,7 +108,8 @@ PhoneNumber.formItemPropsHandler = function (_ref2) {
108
108
  length = _ref2.length,
109
109
  maxLength = _ref2.maxLength,
110
110
  minLength = _ref2.minLength,
111
- label = _ref2.label;
111
+ label = _ref2.label,
112
+ pattern = _ref2.pattern;
112
113
  var rules = [{
113
114
  validator: function validator(rule, value) {
114
115
  if (!value) return Promise.resolve();
@@ -181,6 +182,21 @@ PhoneNumber.formItemPropsHandler = function (_ref2) {
181
182
  });
182
183
  }
183
184
 
185
+ if (pattern) {
186
+ rules.push({
187
+ validator: function validator(_, value) {
188
+ if (value === undefined || value === null || new RegExp(pattern).test(value.phoneNumber)) return Promise.resolve();
189
+ return Promise.reject((0, _locale.staticFormatMessage)({
190
+ id: '{label} must match the pattern {pattern}.',
191
+ values: {
192
+ pattern: pattern,
193
+ label: label
194
+ }
195
+ }));
196
+ }
197
+ });
198
+ }
199
+
184
200
  return {
185
201
  initialValue: phoneNumber ? {
186
202
  areaCode: Array.isArray(areaCode) ? areaCode[0] : areaCode,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "iglooform",
3
- "version": "2.5.26",
3
+ "version": "2.5.27",
4
4
  "scripts": {
5
5
  "start": "dumi dev",
6
6
  "build-dev": "dumi build",