linear-react-components-ui 1.0.10-rc.15 → 1.0.10-rc.17

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.
package/lib/form/index.js CHANGED
@@ -97,6 +97,10 @@ var Form = function Form(_ref) {
97
97
  fieldErrors = _useState8[0],
98
98
  setFieldErrors = _useState8[1];
99
99
  var fieldsValidators = (0, _react.useRef)({});
100
+ var _useState9 = (0, _react.useState)(0),
101
+ _useState10 = _slicedToArray(_useState9, 2),
102
+ oldFieldsValidatorsQuantity = _useState10[0],
103
+ setOldFieldsValidatorsQuantity = _useState10[1];
100
104
  var context = (0, _react.useContext)(_withFormSecurity.FormSecurityContext);
101
105
  var usedData = useInternalState ? data : dataSource;
102
106
  var getValidatesErrorMessages = function getValidatesErrorMessages(validators, fieldValue) {
@@ -170,9 +174,6 @@ var Form = function Form(_ref) {
170
174
  var onRemoveFieldValidators = function onRemoveFieldValidators(fieldName) {
171
175
  var newFieldsValidators = _lodash.default.omit(fieldsValidators, fieldName);
172
176
  fieldsValidators.current = newFieldsValidators;
173
- if (onValidateForm) {
174
- onValidateForm(checkIsValid(usedData, true, fieldsValidators.current));
175
- }
176
177
  };
177
178
  var onBeforeUnload = function onBeforeUnload(e) {
178
179
  var event = e;
@@ -218,7 +219,9 @@ var Form = function Form(_ref) {
218
219
  if (!disabled) {
219
220
  handlerSubmit(onFormSubmit);
220
221
  if (handlerReset) handlerReset(onReset);
221
- if (handlerValidates) handlerValidates(checkIsValid(usedData));
222
+ if (handlerValidates) handlerValidates(function () {
223
+ return checkIsValid(usedData);
224
+ });
222
225
  }
223
226
  if (_lodash.default.isEmpty(usedData)) setOriginalData(usedData);
224
227
  };
@@ -242,15 +245,21 @@ var Form = function Form(_ref) {
242
245
  setSubmitFormOnEnter(submitOnPressEnterKey);
243
246
  }
244
247
  }, [submitOnPressEnterKey]);
248
+ (0, _react.useEffect)(function () {
249
+ var newValidatorsQuantity = Object.values(fieldsValidators.current).reduce(function (acc, currentValue) {
250
+ return acc + ((currentValue === null || currentValue === void 0 ? void 0 : currentValue.length) || 0);
251
+ }, 0);
252
+ if (fieldsValidators.current && onValidateForm && oldFieldsValidatorsQuantity !== newValidatorsQuantity) {
253
+ setOldFieldsValidatorsQuantity(newValidatorsQuantity);
254
+ onValidateForm(checkIsValid(usedData, true, fieldsValidators.current));
255
+ }
256
+ }, [fieldsValidators.current, oldFieldsValidatorsQuantity, onValidateForm, JSON.stringify(usedData)]);
245
257
  var contextValues = {
246
258
  skeletonize: skeletonize,
247
259
  handlerFieldChange: onFieldChange,
248
260
  handlerFieldValidade: onValidate,
249
261
  handlerStoreValidators: function handlerStoreValidators(fieldName, fieldValidates) {
250
262
  fieldsValidators.current = _objectSpread(_objectSpread({}, fieldsValidators.current), {}, _defineProperty({}, fieldName, fieldValidates));
251
- if (onValidateForm) {
252
- onValidateForm(checkIsValid(usedData, true, fieldsValidators.current));
253
- }
254
263
  },
255
264
  handlerRemoveValidators: onRemoveFieldValidators,
256
265
  data: useInternalState ? data : dataSource,
@@ -156,6 +156,7 @@ interface FormContextProps {
156
156
  }
157
157
  interface WithFieldProps {
158
158
  name: string;
159
+ data?: Data;
159
160
  handlerStoreValidators?: (name: string, validators: Validator | Validator[]) => void;
160
161
  handlerRemoveValidators?: (name: string) => void;
161
162
  validators?: Validator | Validator[] | PeriodValidator | PeriodValidator[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "linear-react-components-ui",
3
- "version": "1.0.10-rc.15",
3
+ "version": "1.0.10-rc.17",
4
4
  "description": "Linear Sistemas ReactJs Components",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib/index.cjs",