ab-ui-library 1.42.9 → 1.43.0

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.
@@ -64,9 +64,9 @@ var FormContainer = function FormContainer(props) {
64
64
  getValues = _useForm.getValues,
65
65
  watch = _useForm.watch,
66
66
  reset = _useForm.reset,
67
+ trigger = _useForm.trigger,
67
68
  clearErrors = _useForm.clearErrors,
68
69
  setError = _useForm.setError,
69
- trigger = _useForm.trigger,
70
70
  getFieldState = _useForm.getFieldState,
71
71
  unregister = _useForm.unregister;
72
72
  var errors = formState.errors,
@@ -74,54 +74,100 @@ var FormContainer = function FormContainer(props) {
74
74
  isSubmitted = formState.isSubmitted,
75
75
  isSubmitting = formState.isSubmitting,
76
76
  dirtyFields = formState.dirtyFields;
77
- var customSubmit = /*#__PURE__*/function () {
78
- var _ref = _asyncToGenerator(/*#__PURE__*/regenerator.mark(function _callee(data) {
77
+ var validateForm = /*#__PURE__*/function () {
78
+ var _ref = _asyncToGenerator(/*#__PURE__*/regenerator.mark(function _callee() {
79
79
  return regenerator.wrap(function _callee$(_context) {
80
80
  while (1) switch (_context.prev = _context.next) {
81
81
  case 0:
82
- _context.prev = 0;
83
- if (!validationScheme) {
84
- _context.next = 4;
82
+ if (validationScheme) {
83
+ _context.next = 2;
85
84
  break;
86
85
  }
87
- _context.next = 4;
88
- return validationScheme.validate(data, {
86
+ return _context.abrupt("return", true);
87
+ case 2:
88
+ _context.prev = 2;
89
+ _context.next = 5;
90
+ return validationScheme.validate(getValues(), {
89
91
  abortEarly: false
90
92
  });
91
- case 4:
92
- if (onSubmit) {
93
- onSubmit(data, formState, dirtyFields);
94
- }
95
- _context.next = 10;
96
- break;
97
- case 7:
98
- _context.prev = 7;
99
- _context.t0 = _context["catch"](0);
93
+ case 5:
94
+ return _context.abrupt("return", true);
95
+ case 8:
96
+ _context.prev = 8;
97
+ _context.t0 = _context["catch"](2);
100
98
  if (_context.t0 instanceof yup.ValidationError) {
101
99
  _context.t0.inner.forEach(function (err) {
102
- setError(err.path, {
103
- type: 'manual',
104
- message: err.message
105
- });
100
+ if (err.path) {
101
+ setError(err.path, {
102
+ type: 'manual',
103
+ message: err.message
104
+ });
105
+ }
106
106
  });
107
107
  }
108
- case 10:
108
+ return _context.abrupt("return", false);
109
+ case 12:
109
110
  case "end":
110
111
  return _context.stop();
111
112
  }
112
- }, _callee, null, [[0, 7]]);
113
+ }, _callee, null, [[2, 8]]);
113
114
  }));
114
- return function customSubmit(_x) {
115
+ return function validateForm() {
115
116
  return _ref.apply(this, arguments);
116
117
  };
117
118
  }();
119
+ var customTrigger = /*#__PURE__*/function () {
120
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/regenerator.mark(function _callee2() {
121
+ return regenerator.wrap(function _callee2$(_context2) {
122
+ while (1) switch (_context2.prev = _context2.next) {
123
+ case 0:
124
+ return _context2.abrupt("return", validateForm());
125
+ case 1:
126
+ case "end":
127
+ return _context2.stop();
128
+ }
129
+ }, _callee2);
130
+ }));
131
+ return function customTrigger() {
132
+ return _ref2.apply(this, arguments);
133
+ };
134
+ }();
135
+ var customSubmit = /*#__PURE__*/function () {
136
+ var _ref3 = _asyncToGenerator(/*#__PURE__*/regenerator.mark(function _callee3(data) {
137
+ var isValid;
138
+ return regenerator.wrap(function _callee3$(_context3) {
139
+ while (1) switch (_context3.prev = _context3.next) {
140
+ case 0:
141
+ _context3.next = 2;
142
+ return validateForm();
143
+ case 2:
144
+ isValid = _context3.sent;
145
+ if (isValid) {
146
+ _context3.next = 5;
147
+ break;
148
+ }
149
+ return _context3.abrupt("return");
150
+ case 5:
151
+ if (onSubmit) {
152
+ onSubmit(data, formState, dirtyFields);
153
+ }
154
+ case 6:
155
+ case "end":
156
+ return _context3.stop();
157
+ }
158
+ }, _callee3);
159
+ }));
160
+ return function customSubmit(_x) {
161
+ return _ref3.apply(this, arguments);
162
+ };
163
+ }();
118
164
  return /*#__PURE__*/React.createElement("form", {
119
165
  onSubmit: handleSubmit(customSubmit),
120
166
  id: formId,
121
167
  className: classNames('form-container', className)
122
168
  }, /*#__PURE__*/React.createElement(FormContext.Provider, {
123
169
  value: {
124
- trigger: trigger,
170
+ trigger: mode === 'onSubmit' ? customTrigger : trigger,
125
171
  register: register,
126
172
  errors: errors,
127
173
  control: control,
@@ -132,6 +178,7 @@ var FormContainer = function FormContainer(props) {
132
178
  isDirty: isDirty,
133
179
  isSubmitted: isSubmitted,
134
180
  isSubmitting: isSubmitting,
181
+ isValid: formState.isValid,
135
182
  clearErrors: clearErrors,
136
183
  setError: setError,
137
184
  dirtyFields: dirtyFields,
@@ -17,5 +17,6 @@ export type TFormContextProps = {
17
17
  trigger?: UseFormTrigger<TFormData>;
18
18
  getFieldState?: UseFormGetFieldState<TFormData>;
19
19
  unregister?: UseFormUnregister<TFormData>;
20
+ isValid: boolean;
20
21
  };
21
22
  export declare const FormContext: import("react").Context<TFormContextProps>;
package/context/types.js CHANGED
@@ -6,7 +6,8 @@ var FormContext = /*#__PURE__*/createContext({
6
6
  setValue: noop,
7
7
  isSubmitted: false,
8
8
  isSubmitting: false,
9
- dirtyFields: {}
9
+ dirtyFields: {},
10
+ isValid: false
10
11
  });
11
12
 
12
13
  export { FormContext };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ab-ui-library",
3
- "version": "1.42.9",
3
+ "version": "1.43.0",
4
4
  "description": "UI library for AM",
5
5
  "main": "./index.js",
6
6
  "module": "./index.js",