@domonda/form
Advanced tools
Comparing version 2.2.4 to 2.3.0
@@ -6,2 +6,13 @@ # Change Log | ||
# [2.3.0](https://github.com/domonda/domonda-js/compare/@domonda/form@2.2.4...@domonda/form@2.3.0) (2019-12-02) | ||
### Features | ||
* **Form,FormField:** `transformers` allow the values to be transformed on the fly before notifying any of the subscribers ([7dafca0](https://github.com/domonda/domonda-js/commit/7dafca0e342b7d96f29cc06e6be149e19414c207)) | ||
## [2.2.4](https://github.com/domonda/domonda-js/compare/@domonda/form@2.2.3...@domonda/form@2.2.4) (2019-11-30) | ||
@@ -8,0 +19,0 @@ |
@@ -34,2 +34,19 @@ "use strict"; | ||
readOnly: false, | ||
}, { | ||
transformer: (state, tag) => { | ||
switch (tag) { | ||
case undefined: | ||
case FormTag_1.FormTag.DEFAULT_VALUES_CHANGE: | ||
case FormTag_1.FormTag.VALUES_CHANGE: | ||
case FormTag_1.FormTag.VALUES_RESET: | ||
case FormTag_1.FormTag.FIELD_VALUE_CHANGE: | ||
case FormTag_1.FormTag.FIELD_VALUE_RESET: | ||
case FormTag_1.FormTag.SUBMIT_WITH_DEFAULT_VALUES_CHANGE: { | ||
if (configRef.current.transformer) { | ||
return Object.assign(Object.assign({}, state), { values: configRef.current.transformer(state.values, tag) }); | ||
} | ||
} | ||
} | ||
return state; | ||
}, | ||
}); | ||
@@ -36,0 +53,0 @@ function applyConfig(usingConfig) { |
@@ -49,3 +49,3 @@ "use strict"; | ||
config = {}) { | ||
const { validate, immediateValidate } = config; | ||
const { validate, immediateValidate, transformer } = config; | ||
let disabled = form.state.disabled; | ||
@@ -58,10 +58,15 @@ let readOnly = form.state.readOnly; | ||
selector: (state) => selector(path, state), | ||
transformer: (selectedState) => { | ||
const changed = !fast_equals_1.deepEqual(selectedState.defaultValue, selectedState.value); | ||
transformer: (selectedState, tag) => { | ||
let value = selectedState.value; | ||
if (transformer) { | ||
value = transformer(value, tag); | ||
} | ||
const changed = !fast_equals_1.deepEqual(selectedState.defaultValue, value); | ||
let validityMessage = selectedState.validityMessage; | ||
if (validate && (changed || (immediateValidate && initialTransform))) { | ||
validityMessage = validate(selectedState.value); | ||
validityMessage = validate(value); | ||
} | ||
initialTransform = false; | ||
return Object.assign(Object.assign({}, selectedState), { changed, | ||
return Object.assign(Object.assign({}, selectedState), { value, | ||
changed, | ||
validityMessage }); | ||
@@ -68,0 +73,0 @@ }, |
@@ -7,3 +7,3 @@ /** | ||
import { FormField, FormFieldConfig, FormFieldValidityMessage, FormFieldDispose } from './FormField'; | ||
import { Plumb } from '@domonda/plumb'; | ||
import { Plumb, Transformer } from '@domonda/plumb'; | ||
import { FormTag } from './FormTag'; | ||
@@ -47,2 +47,6 @@ export declare class FormConfigRef<DefaultValues extends FormDefaultValues> { | ||
el?: HTMLFormElement | null; | ||
/** | ||
* Transforms values before dispatching notifications to subscribers. | ||
*/ | ||
transformer?: Transformer<T, FormTag>; | ||
} | ||
@@ -49,0 +53,0 @@ export interface FormFieldState { |
@@ -7,3 +7,3 @@ /** | ||
import { FormFieldState } from './Form'; | ||
import { Plumb } from '@domonda/plumb'; | ||
import { Plumb, Transformer } from '@domonda/plumb'; | ||
import { FormTag } from './FormTag'; | ||
@@ -21,2 +21,3 @@ export interface FormFieldStateWithValues<T> extends FormFieldState { | ||
immediateValidate?: boolean; | ||
transformer?: Transformer<T, FormTag>; | ||
} | ||
@@ -23,0 +24,0 @@ export interface FormField<T> { |
{ | ||
"name": "@domonda/form", | ||
"version": "2.2.4", | ||
"version": "2.3.0", | ||
"description": "Powerful yet simple form library built using @domonda/plumb.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
28695
498