@beinformed/ui 1.17.1 → 1.17.2

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/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [1.17.2](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.17.1...v1.17.2) (2022-04-07)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * **validate:** Added useAttributeValidate to validate the attribute onBlur ([#17](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/issues/17)) ([426b592](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/commit/426b592015cf07d2c35d1708a54b7d68b6ab9cec))
11
+
5
12
  ### [1.17.1](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.17.0...v1.17.1) (2022-03-30)
6
13
 
7
14
  ### Bug Fixes
@@ -3,7 +3,7 @@ import Href from "../models/href/Href";
3
3
  import { getSetting, HTTP_METHODS } from "../constants";
4
4
  import { loadModularUI, removeModelByKey } from "../redux/_modularui";
5
5
  import { useModularUI } from "./useModularUI";
6
- import { addRepeatableAttributeSet, cancelForm, cancelRepeatableAttributeSet, previousObject, removeRepeatableAttributeSet, showFormNotification, updateFormAttribute } from "../redux/actions";
6
+ import { addRepeatableAttributeSet, cancelForm, cancelRepeatableAttributeSet, previousObject, removeRepeatableAttributeSet, showFormNotification, updateFormAttribute, validateFormAttribute } from "../redux/actions";
7
7
  import FormModel from "../models/form/FormModel";
8
8
 
9
9
  /**
@@ -76,6 +76,16 @@ export var useAttributeUpdate = function useAttributeUpdate(form, object) {
76
76
  return dispatch(updateFormAttribute(form, object, attribute, value, options));
77
77
  };
78
78
  };
79
+ /**
80
+ * Validate attributes of a form
81
+ */
82
+
83
+ export var useAttributeValidate = function useAttributeValidate(form) {
84
+ var dispatch = useDispatch();
85
+ return function () {
86
+ return dispatch(validateFormAttribute(form));
87
+ };
88
+ };
79
89
  /**
80
90
  * Attributeset actions
81
91
  */
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/hooks/useForm.js"],"names":["useDispatch","Href","getSetting","HTTP_METHODS","loadModularUI","removeModelByKey","useModularUI","addRepeatableAttributeSet","cancelForm","cancelRepeatableAttributeSet","previousObject","removeRepeatableAttributeSet","showFormNotification","updateFormAttribute","FormModel","useForm","href","formHref","addParameter","form","method","POST","targetModel","removeOnUnmount","model","useFormNavigation","dispatch","previous","cancel","submit","connectKey","selfhref","data","formdata","updateModel","remove","showFormNotificationAction","useAttributeUpdate","object","attribute","value","options","useAttributeSet","save"],"mappings":"AACA,SAASA,WAAT,QAA4B,aAA5B;AAEA,OAAOC,IAAP,MAAiB,qBAAjB;AAEA,SAASC,UAAT,EAAqBC,YAArB,QAAyC,cAAzC;AAEA,SAASC,aAAT,EAAwBC,gBAAxB,QAAgD,qBAAhD;AACA,SAASC,YAAT,QAA6B,gBAA7B;AAEA,SACEC,yBADF,EAEEC,UAFF,EAGEC,4BAHF,EAIEC,cAJF,EAKEC,4BALF,EAMEC,oBANF,EAOEC,mBAPF,QAQO,kBARP;AAUA,OAAOC,SAAP,MAAsB,0BAAtB;;AA6BA;AACA;AACA;AACA,OAAO,IAAMC,OAAO,GAAG,SAAVA,OAAU,CAACC,IAAD,EAAqC;AAC1D,MAAMC,QAAQ,GAAG,IAAIhB,IAAJ,CAASe,IAAT,CAAjB;;AAEA,MAAI,CAACd,UAAU,CAAC,oBAAD,CAAf,EAAuC;AACrCe,IAAAA,QAAQ,CAACC,YAAT,CAAsB,QAAtB,EAAgC,OAAhC;AACD;;AAED,MAAMC,IAAI,GAAGb,YAAY,CAAC,MAAD,EAASW,QAAT,EAAmB;AAC1CG,IAAAA,MAAM,EAAEjB,YAAY,CAACkB,IADqB;AAE1CC,IAAAA,WAAW,EAAER,SAF6B;AAG1CS,IAAAA,eAAe,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ILM,IAAAA,MAAM,EAANA,MAJK;AAKLvB,IAAAA,oBAAoB,EAAEwB;AALjB,GAAP;AAOD,CA9BM;AAgCP;AACA;AACA;;AACA,OAAO,IAAMC,kBAAkB,GAAG,SAArBA,kBAAqB,CAChClB,IADgC,EAEhCmB,MAFgC,EAGR;AACxB,MAAMZ,QAAQ,GAAG1B,WAAW,EAA5B;AAEA,SAAO,UACLuC,SADK,EAELC,KAFK,EAGLC,OAHK;AAAA,WAIFf,QAAQ,CAACb,mBAAmB,CAACM,IAAD,EAAOmB,MAAP,EAAeC,SAAf,EAA0BC,KAA1B,EAAiCC,OAAjC,CAApB,CAJN;AAAA,GAAP;AAKD,CAXM;AAaP;AACA;AACA;;AACA,OAAO,IAAMC,eAAe,GAAG,SAAlBA,eAAkB,CAACvB,IAAD,EAAuC;AACpE,MAAMO,QAAQ,GAAG1B,WAAW,EAA5B;AAEA,SAAO;AACL2C,IAAAA,IAAI,EAAE;AAAA,aAAMjB,QAAQ,CAACnB,yBAAyB,CAACY,IAAD,CAA1B,CAAd;AAAA,KADD;AAELS,IAAAA,MAAM,EAAE,gBAACU,MAAD;AAAA,aACNZ,QAAQ,CAACjB,4BAA4B,CAACU,IAAD,EAAOmB,MAAP,CAA7B,CADF;AAAA,KAFH;AAILH,IAAAA,MAAM,EAAE,gBAACG,MAAD;AAAA,aACNZ,QAAQ,CAACf,4BAA4B,CAACQ,IAAD,EAAOmB,MAAP,CAA7B,CADF;AAAA;AAJH,GAAP;AAOD,CAVM","sourcesContent":["// @flow\nimport { useDispatch } from \"react-redux\";\n\nimport Href from \"../models/href/Href\";\n\nimport { getSetting, HTTP_METHODS } from \"../constants\";\n\nimport { loadModularUI, removeModelByKey } from \"../redux/_modularui\";\nimport { useModularUI } from \"./useModularUI\";\n\nimport {\n addRepeatableAttributeSet,\n cancelForm,\n cancelRepeatableAttributeSet,\n previousObject,\n removeRepeatableAttributeSet,\n showFormNotification,\n updateFormAttribute,\n} from \"../redux/actions\";\n\nimport FormModel from \"../models/form/FormModel\";\n\nimport type { FormObjectModel, AttributeType } from \"../models\";\nimport type { UpdateFormOptions } from \"../redux/types\";\nimport type {\n RemoveModelByKeyAction,\n UpdateModelAction,\n} from \"../redux/_modularui\";\n\ntype FormNavigationHook = {\n previous: (form: FormModel) => UpdateModelAction,\n cancel: (form: FormModel) => void,\n submit: (form: FormModel) => void,\n showFormNotification: (form: FormModel) => void,\n remove: (form: FormModel) => RemoveModelByKeyAction,\n};\n\ntype AttributeSetHook = {\n save: () => UpdateModelAction,\n cancel: (object: FormObjectModel) => UpdateModelAction,\n remove: (object: FormObjectModel) => UpdateModelAction,\n};\n\ntype AttributeUpdateHook = (\n attribute: AttributeType,\n value: string,\n options: UpdateFormOptions\n) => void;\n\n/**\n * Load a form by href\n */\nexport const useForm = (href: string | Href): ?FormModel => {\n const formHref = new Href(href);\n\n if (!getSetting(\"ALWAYS_COMMIT_FORM\")) {\n formHref.addParameter(\"commit\", \"false\");\n }\n\n const form = useModularUI(\"form\", formHref, {\n method: HTTP_METHODS.POST,\n targetModel: FormModel,\n removeOnUnmount: true,\n });\n\n if (form?.model) {\n return form.model;\n }\n};\n\n/**\n * Form navigation methods\n */\nexport const useFormNavigation = (): FormNavigationHook => {\n const dispatch = useDispatch();\n\n const previous = (form: FormModel) => dispatch(previousObject(form));\n\n const cancel = (form: FormModel) => dispatch(cancelForm(form));\n\n const submit = (form: FormModel) =>\n dispatch(\n loadModularUI(form.connectKey, form.selfhref, {\n method: HTTP_METHODS.POST,\n data: form.formdata,\n updateModel: form,\n targetModel: FormModel,\n })\n );\n\n const remove = (form: FormModel) =>\n dispatch(removeModelByKey(form.connectKey));\n\n const showFormNotificationAction = (form: FormModel) =>\n dispatch(showFormNotification(form));\n\n return {\n previous,\n cancel,\n submit,\n remove,\n showFormNotification: showFormNotificationAction,\n };\n};\n\n/**\n * Update attributes of a form\n */\nexport const useAttributeUpdate = (\n form: FormModel,\n object: FormObjectModel\n): AttributeUpdateHook => {\n const dispatch = useDispatch();\n\n return (\n attribute: AttributeType,\n value: string,\n options: UpdateFormOptions\n ) => dispatch(updateFormAttribute(form, object, attribute, value, options));\n};\n\n/**\n * Attributeset actions\n */\nexport const useAttributeSet = (form: FormModel): AttributeSetHook => {\n const dispatch = useDispatch();\n\n return {\n save: () => dispatch(addRepeatableAttributeSet(form)),\n cancel: (object: FormObjectModel) =>\n dispatch(cancelRepeatableAttributeSet(form, object)),\n remove: (object: FormObjectModel) =>\n dispatch(removeRepeatableAttributeSet(form, object)),\n };\n};\n"],"file":"useForm.js"}
1
+ {"version":3,"sources":["../../src/hooks/useForm.js"],"names":["useDispatch","Href","getSetting","HTTP_METHODS","loadModularUI","removeModelByKey","useModularUI","addRepeatableAttributeSet","cancelForm","cancelRepeatableAttributeSet","previousObject","removeRepeatableAttributeSet","showFormNotification","updateFormAttribute","validateFormAttribute","FormModel","useForm","href","formHref","addParameter","form","method","POST","targetModel","removeOnUnmount","model","useFormNavigation","dispatch","previous","cancel","submit","connectKey","selfhref","data","formdata","updateModel","remove","showFormNotificationAction","useAttributeUpdate","object","attribute","value","options","useAttributeValidate","useAttributeSet","save"],"mappings":"AACA,SAASA,WAAT,QAA4B,aAA5B;AAEA,OAAOC,IAAP,MAAiB,qBAAjB;AAEA,SAASC,UAAT,EAAqBC,YAArB,QAAyC,cAAzC;AAEA,SAASC,aAAT,EAAwBC,gBAAxB,QAAgD,qBAAhD;AACA,SAASC,YAAT,QAA6B,gBAA7B;AAEA,SACEC,yBADF,EAEEC,UAFF,EAGEC,4BAHF,EAIEC,cAJF,EAKEC,4BALF,EAMEC,oBANF,EAOEC,mBAPF,EAQEC,qBARF,QASO,kBATP;AAWA,OAAOC,SAAP,MAAsB,0BAAtB;;AA6BA;AACA;AACA;AACA,OAAO,IAAMC,OAAO,GAAG,SAAVA,OAAU,CAACC,IAAD,EAAqC;AAC1D,MAAMC,QAAQ,GAAG,IAAIjB,IAAJ,CAASgB,IAAT,CAAjB;;AAEA,MAAI,CAACf,UAAU,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,IAAD,EAAOmB,MAAP,CAA7B,CADF;AAAA,KAFH;AAILH,IAAAA,MAAM,EAAE,gBAACG,MAAD;AAAA,aACNZ,QAAQ,CAAChB,4BAA4B,CAACS,IAAD,EAAOmB,MAAP,CAA7B,CADF;AAAA;AAJH,GAAP;AAOD,CAVM","sourcesContent":["// @flow\nimport { useDispatch } from \"react-redux\";\n\nimport Href from \"../models/href/Href\";\n\nimport { getSetting, HTTP_METHODS } from \"../constants\";\n\nimport { loadModularUI, removeModelByKey } from \"../redux/_modularui\";\nimport { useModularUI } from \"./useModularUI\";\n\nimport {\n addRepeatableAttributeSet,\n cancelForm,\n cancelRepeatableAttributeSet,\n previousObject,\n removeRepeatableAttributeSet,\n showFormNotification,\n updateFormAttribute,\n validateFormAttribute,\n} from \"../redux/actions\";\n\nimport FormModel from \"../models/form/FormModel\";\n\nimport type { FormObjectModel, AttributeType } from \"../models\";\nimport type { UpdateFormOptions } from \"../redux/types\";\nimport type {\n RemoveModelByKeyAction,\n UpdateModelAction,\n} from \"../redux/_modularui\";\n\ntype FormNavigationHook = {\n previous: (form: FormModel) => UpdateModelAction,\n cancel: (form: FormModel) => void,\n submit: (form: FormModel) => void,\n showFormNotification: (form: FormModel) => void,\n remove: (form: FormModel) => RemoveModelByKeyAction,\n};\n\ntype AttributeSetHook = {\n save: () => UpdateModelAction,\n cancel: (object: FormObjectModel) => UpdateModelAction,\n remove: (object: FormObjectModel) => UpdateModelAction,\n};\n\ntype AttributeUpdateHook = (\n attribute: AttributeType,\n value: string,\n options: UpdateFormOptions\n) => void;\n\n/**\n * Load a form by href\n */\nexport const useForm = (href: string | Href): ?FormModel => {\n const formHref = new Href(href);\n\n if (!getSetting(\"ALWAYS_COMMIT_FORM\")) {\n formHref.addParameter(\"commit\", \"false\");\n }\n\n const form = useModularUI(\"form\", formHref, {\n method: HTTP_METHODS.POST,\n targetModel: FormModel,\n removeOnUnmount: true,\n });\n\n if (form?.model) {\n return form.model;\n }\n};\n\n/**\n * Form navigation methods\n */\nexport const useFormNavigation = (): FormNavigationHook => {\n const dispatch = useDispatch();\n\n const previous = (form: FormModel) => dispatch(previousObject(form));\n\n const cancel = (form: FormModel) => dispatch(cancelForm(form));\n\n const submit = (form: FormModel) =>\n dispatch(\n loadModularUI(form.connectKey, form.selfhref, {\n method: HTTP_METHODS.POST,\n data: form.formdata,\n updateModel: form,\n targetModel: FormModel,\n })\n );\n\n const remove = (form: FormModel) =>\n dispatch(removeModelByKey(form.connectKey));\n\n const showFormNotificationAction = (form: FormModel) =>\n dispatch(showFormNotification(form));\n\n return {\n previous,\n cancel,\n submit,\n remove,\n showFormNotification: showFormNotificationAction,\n };\n};\n\n/**\n * Update attributes of a form\n */\nexport const useAttributeUpdate = (\n form: FormModel,\n object: FormObjectModel\n): AttributeUpdateHook => {\n const dispatch = useDispatch();\n\n return (\n attribute: AttributeType,\n value: string,\n options: UpdateFormOptions\n ) => dispatch(updateFormAttribute(form, object, attribute, value, options));\n};\n\n/**\n * Validate attributes of a form\n */\nexport const useAttributeValidate = (form: FormModel): AttributeUpdateHook => {\n const dispatch = useDispatch();\n\n return () => dispatch(validateFormAttribute(form));\n};\n\n/**\n * Attributeset actions\n */\nexport const useAttributeSet = (form: FormModel): AttributeSetHook => {\n const dispatch = useDispatch();\n\n return {\n save: () => dispatch(addRepeatableAttributeSet(form)),\n cancel: (object: FormObjectModel) =>\n dispatch(cancelRepeatableAttributeSet(form, object)),\n remove: (object: FormObjectModel) =>\n dispatch(removeRepeatableAttributeSet(form, object)),\n };\n};\n"],"file":"useForm.js"}
@@ -17,7 +17,7 @@ export var updateFormAttribute = function updateFormAttribute(form, formObject,
17
17
  return function (dispatch) {
18
18
  var newForm = form.clone();
19
19
 
20
- if (!options.validate) {
20
+ if (options.validate === undefined) {
21
21
  options.validate = true;
22
22
  }
23
23
 
@@ -50,4 +50,13 @@ export var updateFormAttribute = function updateFormAttribute(form, formObject,
50
50
  return dispatch(updateModel(newForm));
51
51
  };
52
52
  };
53
+ /**
54
+ * Validate an attribute on a form
55
+ */
56
+
57
+ export var validateFormAttribute = function validateFormAttribute(form) {
58
+ return function (dispatch) {
59
+ return dispatch(validateFormObject(form));
60
+ };
61
+ };
53
62
  //# sourceMappingURL=FormAttributeSet.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/redux/actions/FormAttributeSet.js"],"names":["updateModel","getSetting","validateFormObject","autosaveFormObject","autosubmitFormObject","updateFormAttribute","form","formObject","attribute","inputvalue","options","autosubmit","autosave","forceUpdate","validate","dispatch","newForm","clone","currentFormObject","equals","updateAttribute","completedFormObjects","forEach","completeObject","isValid","autosubmitAction","isChanged","hasDynamicValidations"],"mappings":"AACA,SAASA,WAAT,QAA4B,uBAA5B;AAEA,SAASC,UAAT,QAA2B,0BAA3B;AAEA,SAASC,kBAAT,QAAmC,mBAAnC;AACA,SAASC,kBAAT,QAAmC,gBAAnC;AACA,SAASC,oBAAT,QAAqC,kBAArC;;AAOA;AACA;AACA;AACA,OAAO,IAAMC,mBAAmB,GAC9B,SADWA,mBACX,CACEC,IADF,EAEEC,UAFF,EAGEC,SAHF,EAIEC,UAJF;AAAA,MAKEC,OALF,uEAK+B;AAC3BC,IAAAA,UAAU,EAAE,KADe;AAE3BC,IAAAA,QAAQ,EAAE,KAFiB;AAG3BC,IAAAA,WAAW,EAAE,KAHc;AAI3BC,IAAAA,QAAQ,EAAE;AAJiB,GAL/B;AAAA,SAYA,UAACC,QAAD,EAAwB;AACtB,QAAMC,OAAO,GAAGV,IAAI,CAACW,KAAL,EAAhB;;AAEA,QAAI,CAACP,OAAO,CAACI,QAAb,EAAuB;AACrBJ,MAAAA,OAAO,CAACI,QAAR,GAAmB,IAAnB;AACD;;AAED,QACEE,OAAO,CAACE,iBAAR,IACAF,OAAO,CAACE,iBAAR,CAA0BC,MAA1B,CAAiCZ,UAAjC,CAFF,EAGE;AACAS,MAAAA,OAAO,CAACE,iBAAR,CAA0BE,eAA1B,CAA0CZ,SAA1C,EAAqDC,UAArD;AACD,KALD,MAKO;AACLO,MAAAA,OAAO,CAACK,oBAAR,CAA6BC,OAA7B,CAAqC,UAACC,cAAD,EAAoB;AACvD,YAAIA,cAAc,CAACJ,MAAf,CAAsBZ,UAAtB,CAAJ,EAAuC;AACrCgB,UAAAA,cAAc,CAACH,eAAf,CAA+BZ,SAA/B,EAA0CC,UAA1C;AACD;AACF,OAJD;AAKD;;AAED,QAAIC,OAAO,CAACC,UAAR,IAAsBK,OAAO,CAACQ,OAAlC,EAA2C;AACzC,UAAMC,gBAAgB,GAAGrB,oBAAoB,CAC3CY,OAD2C,EAE3CR,SAF2C,EAG3CE,OAAO,CAACG,WAHmC,CAA7C;;AAKA,UAAIY,gBAAJ,EAAsB;AACpB,eAAOV,QAAQ,CAACU,gBAAD,CAAf;AACD;AACF;;AAED,QAAIf,OAAO,CAACE,QAAR,IAAoBI,OAAO,CAACQ,OAA5B,IAAuCR,OAAO,CAACU,SAAR,EAA3C,EAAgE;AAC9DX,MAAAA,QAAQ,CAACZ,kBAAkB,CAACa,OAAD,CAAnB,CAAR;AACD;;AAED,QACEA,OAAO,CAACE,iBAAR,IACAR,OAAO,CAACI,QADR,IAEAE,OAAO,CAACE,iBAAR,CAA0BS,qBAF1B,IAGA1B,UAAU,CAAC,+BAAD,CAJZ,EAKE;AACAc,MAAAA,QAAQ,CAACb,kBAAkB,CAACc,OAAD,CAAnB,CAAR;AACD;;AAED,WAAOD,QAAQ,CAACf,WAAW,CAACgB,OAAD,CAAZ,CAAf;AACD,GAzDD;AAAA,CADK","sourcesContent":["// @flow\nimport { updateModel } from \"../_modularui/actions\";\n\nimport { getSetting } from \"../../constants/Settings\";\n\nimport { validateFormObject } from \"./FormValidations\";\nimport { autosaveFormObject } from \"./FormAutosave\";\nimport { autosubmitFormObject } from \"./FormAutosubmit\";\n\nimport type { Dispatch, ThunkAction, UpdateFormOptions } from \"../types\";\nimport type { AttributeType } from \"../../models/types\";\nimport type FormModel from \"../../models/form/FormModel\";\nimport type FormObjectModel from \"../../models/form/FormObjectModel\";\n\n/**\n * Update an attribute on a form\n */\nexport const updateFormAttribute =\n (\n form: FormModel,\n formObject: FormObjectModel,\n attribute: AttributeType,\n inputvalue: string,\n options: UpdateFormOptions = {\n autosubmit: false,\n autosave: false,\n forceUpdate: false,\n validate: true,\n }\n ): ThunkAction =>\n (dispatch: Dispatch) => {\n const newForm = form.clone();\n\n if (!options.validate) {\n options.validate = true;\n }\n\n if (\n newForm.currentFormObject &&\n newForm.currentFormObject.equals(formObject)\n ) {\n newForm.currentFormObject.updateAttribute(attribute, inputvalue);\n } else {\n newForm.completedFormObjects.forEach((completeObject) => {\n if (completeObject.equals(formObject)) {\n completeObject.updateAttribute(attribute, inputvalue);\n }\n });\n }\n\n if (options.autosubmit && newForm.isValid) {\n const autosubmitAction = autosubmitFormObject(\n newForm,\n attribute,\n options.forceUpdate\n );\n if (autosubmitAction) {\n return dispatch(autosubmitAction);\n }\n }\n\n if (options.autosave && newForm.isValid && newForm.isChanged()) {\n dispatch(autosaveFormObject(newForm));\n }\n\n if (\n newForm.currentFormObject &&\n options.validate &&\n newForm.currentFormObject.hasDynamicValidations &&\n getSetting(\"USE_INSTANT_SERVER_VALIDATION\")\n ) {\n dispatch(validateFormObject(newForm));\n }\n\n return dispatch(updateModel(newForm));\n };\n"],"file":"FormAttributeSet.js"}
1
+ {"version":3,"sources":["../../../src/redux/actions/FormAttributeSet.js"],"names":["updateModel","getSetting","validateFormObject","autosaveFormObject","autosubmitFormObject","updateFormAttribute","form","formObject","attribute","inputvalue","options","autosubmit","autosave","forceUpdate","validate","dispatch","newForm","clone","undefined","currentFormObject","equals","updateAttribute","completedFormObjects","forEach","completeObject","isValid","autosubmitAction","isChanged","hasDynamicValidations","validateFormAttribute"],"mappings":"AACA,SAASA,WAAT,QAA4B,uBAA5B;AAEA,SAASC,UAAT,QAA2B,0BAA3B;AAEA,SAASC,kBAAT,QAAmC,mBAAnC;AACA,SAASC,kBAAT,QAAmC,gBAAnC;AACA,SAASC,oB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,OAAO,CAACW,SAAR,EAA3C,EAAgE;AAC9DZ,MAAAA,QAAQ,CAACZ,kBAAkB,CAACa,OAAD,CAAnB,CAAR;AACD;;AAED,QACEA,OAAO,CAACG,iBAAR,IACAT,OAAO,CAACI,QADR,IAEAE,OAAO,CAACG,iBAAR,CAA0BS,qBAF1B,IAGA3B,UAAU,CAAC,+BAAD,CAJZ,EAKE;AACAc,MAAAA,QAAQ,CAACb,kBAAkB,CAACc,OAAD,CAAnB,CAAR;AACD;;AAED,WAAOD,QAAQ,CAACf,WAAW,CAACgB,OAAD,CAAZ,CAAf;AACD,GAzDD;AAAA,CADK;AA4DP;AACA;AACA;;AACA,OAAO,IAAMa,qBAAqB,GAChC,SADWA,qBACX,CAACvB,IAAD;AAAA,SACA,UAACS,QAAD,EAAwB;AACtB,WAAOA,QAAQ,CAACb,kBAAkB,CAACI,IAAD,CAAnB,CAAf;AACD,GAHD;AAAA,CADK","sourcesContent":["// @flow\nimport { updateModel } from \"../_modularui/actions\";\n\nimport { getSetting } from \"../../constants/Settings\";\n\nimport { validateFormObject } from \"./FormValidations\";\nimport { autosaveFormObject } from \"./FormAutosave\";\nimport { autosubmitFormObject } from \"./FormAutosubmit\";\n\nimport type { Dispatch, ThunkAction, UpdateFormOptions } from \"../types\";\nimport type { AttributeType } from \"../../models/types\";\nimport type FormModel from \"../../models/form/FormModel\";\nimport type FormObjectModel from \"../../models/form/FormObjectModel\";\n\n/**\n * Update an attribute on a form\n */\nexport const updateFormAttribute =\n (\n form: FormModel,\n formObject: FormObjectModel,\n attribute: AttributeType,\n inputvalue: string,\n options: UpdateFormOptions = {\n autosubmit: false,\n autosave: false,\n forceUpdate: false,\n validate: true,\n }\n ): ThunkAction =>\n (dispatch: Dispatch) => {\n const newForm = form.clone();\n\n if (options.validate === undefined) {\n options.validate = true;\n }\n\n if (\n newForm.currentFormObject &&\n newForm.currentFormObject.equals(formObject)\n ) {\n newForm.currentFormObject.updateAttribute(attribute, inputvalue);\n } else {\n newForm.completedFormObjects.forEach((completeObject) => {\n if (completeObject.equals(formObject)) {\n completeObject.updateAttribute(attribute, inputvalue);\n }\n });\n }\n\n if (options.autosubmit && newForm.isValid) {\n const autosubmitAction = autosubmitFormObject(\n newForm,\n attribute,\n options.forceUpdate\n );\n if (autosubmitAction) {\n return dispatch(autosubmitAction);\n }\n }\n\n if (options.autosave && newForm.isValid && newForm.isChanged()) {\n dispatch(autosaveFormObject(newForm));\n }\n\n if (\n newForm.currentFormObject &&\n options.validate &&\n newForm.currentFormObject.hasDynamicValidations &&\n getSetting(\"USE_INSTANT_SERVER_VALIDATION\")\n ) {\n dispatch(validateFormObject(newForm));\n }\n\n return dispatch(updateModel(newForm));\n };\n\n/**\n * Validate an attribute on a form\n */\nexport const validateFormAttribute =\n (form: FormModel): ThunkAction =>\n (dispatch: Dispatch) => {\n return dispatch(validateFormObject(form));\n };\n"],"file":"FormAttributeSet.js"}
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequ
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.useFormNavigation = exports.useForm = exports.useAttributeUpdate = exports.useAttributeSet = void 0;
8
+ exports.useFormNavigation = exports.useForm = exports.useAttributeValidate = exports.useAttributeUpdate = exports.useAttributeSet = void 0;
9
9
 
10
10
  var _reactRedux = require("react-redux");
11
11
 
@@ -98,12 +98,25 @@ var useAttributeUpdate = function useAttributeUpdate(form, object) {
98
98
  };
99
99
  };
100
100
  /**
101
- * Attributeset actions
101
+ * Validate attributes of a form
102
102
  */
103
103
 
104
104
 
105
105
  exports.useAttributeUpdate = useAttributeUpdate;
106
106
 
107
+ var useAttributeValidate = function useAttributeValidate(form) {
108
+ var dispatch = (0, _reactRedux.useDispatch)();
109
+ return function () {
110
+ return dispatch((0, _actions.validateFormAttribute)(form));
111
+ };
112
+ };
113
+ /**
114
+ * Attributeset actions
115
+ */
116
+
117
+
118
+ exports.useAttributeValidate = useAttributeValidate;
119
+
107
120
  var useAttributeSet = function useAttributeSet(form) {
108
121
  var dispatch = (0, _reactRedux.useDispatch)();
109
122
  return {
@@ -16,6 +16,7 @@ import {
16
16
  removeRepeatableAttributeSet,
17
17
  showFormNotification,
18
18
  updateFormAttribute,
19
+ validateFormAttribute,
19
20
  } from "../redux/actions";
20
21
 
21
22
  import FormModel from "../models/form/FormModel";
@@ -119,6 +120,15 @@ export const useAttributeUpdate = (
119
120
  ) => dispatch(updateFormAttribute(form, object, attribute, value, options));
120
121
  };
121
122
 
123
+ /**
124
+ * Validate attributes of a form
125
+ */
126
+ export const useAttributeValidate = (form: FormModel): AttributeUpdateHook => {
127
+ const dispatch = useDispatch();
128
+
129
+ return () => dispatch(validateFormAttribute(form));
130
+ };
131
+
122
132
  /**
123
133
  * Attributeset actions
124
134
  */
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/hooks/useForm.js"],"names":["useForm","href","formHref","Href","addParameter","form","method","HTTP_METHODS","POST","targetModel","FormModel","removeOnUnmount","model","useFormNavigation","dispatch","previous","cancel","submit","connectKey","selfhref","data","formdata","updateModel","remove","showFormNotificationAction","showFormNotification","useAttributeUpdate","object","attribute","value","options","useAttributeSet","save"],"mappings":";;;;;;;;;AACA;;AAEA;;AAEA;;AAEA;;AACA;;AAEA;;AAUA;;AA6BA;AACA;AACA;AACO,IAAMA,OAAO,GAAG,SAAVA,OAAU,CAACC,IAAD,EAAqC;AAC1D,MAAMC,QAAQ,GAAG,IAAIC,aAAJ,CAASF,IAAT,CAAjB;;AAEA,MAAI,CAAC,2BAAW,oBAAX,CAAL,EAAuC;AACrCC,IAAAA,QAAQ,CAACE,YAAT,CAAsB,QAAtB,EAAgC,OAAhC;AACD;;AAED,MAAMC,IAAI,GAAG,gCAAa,MAAb,EAAqBH,QAArB,EAA+B;AAC1CI,IAAAA,MAAM,EAAEC,wBAAaC,IADqB;AAE1CC,IAAAA,WAAW,EAAEC,kBAF6B;AAG1CC,IAAAA,eAAe,EAAE;AAHyB,GAA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AALjB,GAAP;AAOD,CA9BM;AAgCP;AACA;AACA;;;;;AACO,IAAME,kBAAkB,GAAG,SAArBA,kBAAqB,CAChCrB,IADgC,EAEhCsB,MAFgC,EAGR;AACxB,MAAMb,QAAQ,GAAG,8BAAjB;AAEA,SAAO,UACLc,SADK,EAELC,KAFK,EAGLC,OAHK;AAAA,WAIFhB,QAAQ,CAAC,kCAAoBT,IAApB,EAA0BsB,MAA1B,EAAkCC,SAAlC,EAA6CC,KAA7C,EAAoDC,OAApD,CAAD,CAJN;AAAA,GAAP;AAKD,CAXM;AAaP;AACA;AACA;;;;;AACO,IAAMC,eAAe,GAAG,SAAlBA,eAAkB,CAAC1B,IAAD,EAAuC;AACpE,MAAMS,QAAQ,GAAG,8BAAjB;AAEA,SAAO;AACLkB,IAAAA,IAAI,EAAE;AAAA,aAAMlB,QAAQ,CAAC,wCAA0BT,IAA1B,CAAD,CAAd;AAAA,KADD;AAELW,IAAAA,MAAM,EAAE,gBAACW,MAAD;AAAA,aACNb,QAAQ,CAAC,2CAA6BT,IAA7B,EAAmCsB,MAAnC,CAAD,CADF;AAAA,KAFH;AAILJ,IAAAA,MAAM,EAAE,gBAACI,MAAD;AAAA,aACNb,QAAQ,CAAC,2CAA6BT,IAA7B,EAAmCsB,MAAnC,CAAD,CADF;AAAA;AAJH,GAAP;AAOD,CAVM","sourcesContent":["// @flow\nimport { useDispatch } from \"react-redux\";\n\nimport Href from \"../models/href/Href\";\n\nimport { getSetting, HTTP_METHODS } from \"../constants\";\n\nimport { loadModularUI, removeModelByKey } from \"../redux/_modularui\";\nimport { useModularUI } from \"./useModularUI\";\n\nimport {\n addRepeatableAttributeSet,\n cancelForm,\n cancelRepeatableAttributeSet,\n previousObject,\n removeRepeatableAttributeSet,\n showFormNotification,\n updateFormAttribute,\n} from \"../redux/actions\";\n\nimport FormModel from \"../models/form/FormModel\";\n\nimport type { FormObjectModel, AttributeType } from \"../models\";\nimport type { UpdateFormOptions } from \"../redux/types\";\nimport type {\n RemoveModelByKeyAction,\n UpdateModelAction,\n} from \"../redux/_modularui\";\n\ntype FormNavigationHook = {\n previous: (form: FormModel) => UpdateModelAction,\n cancel: (form: FormModel) => void,\n submit: (form: FormModel) => void,\n showFormNotification: (form: FormModel) => void,\n remove: (form: FormModel) => RemoveModelByKeyAction,\n};\n\ntype AttributeSetHook = {\n save: () => UpdateModelAction,\n cancel: (object: FormObjectModel) => UpdateModelAction,\n remove: (object: FormObjectModel) => UpdateModelAction,\n};\n\ntype AttributeUpdateHook = (\n attribute: AttributeType,\n value: string,\n options: UpdateFormOptions\n) => void;\n\n/**\n * Load a form by href\n */\nexport const useForm = (href: string | Href): ?FormModel => {\n const formHref = new Href(href);\n\n if (!getSetting(\"ALWAYS_COMMIT_FORM\")) {\n formHref.addParameter(\"commit\", \"false\");\n }\n\n const form = useModularUI(\"form\", formHref, {\n method: HTTP_METHODS.POST,\n targetModel: FormModel,\n removeOnUnmount: true,\n });\n\n if (form?.model) {\n return form.model;\n }\n};\n\n/**\n * Form navigation methods\n */\nexport const useFormNavigation = (): FormNavigationHook => {\n const dispatch = useDispatch();\n\n const previous = (form: FormModel) => dispatch(previousObject(form));\n\n const cancel = (form: FormModel) => dispatch(cancelForm(form));\n\n const submit = (form: FormModel) =>\n dispatch(\n loadModularUI(form.connectKey, form.selfhref, {\n method: HTTP_METHODS.POST,\n data: form.formdata,\n updateModel: form,\n targetModel: FormModel,\n })\n );\n\n const remove = (form: FormModel) =>\n dispatch(removeModelByKey(form.connectKey));\n\n const showFormNotificationAction = (form: FormModel) =>\n dispatch(showFormNotification(form));\n\n return {\n previous,\n cancel,\n submit,\n remove,\n showFormNotification: showFormNotificationAction,\n };\n};\n\n/**\n * Update attributes of a form\n */\nexport const useAttributeUpdate = (\n form: FormModel,\n object: FormObjectModel\n): AttributeUpdateHook => {\n const dispatch = useDispatch();\n\n return (\n attribute: AttributeType,\n value: string,\n options: UpdateFormOptions\n ) => dispatch(updateFormAttribute(form, object, attribute, value, options));\n};\n\n/**\n * Attributeset actions\n */\nexport const useAttributeSet = (form: FormModel): AttributeSetHook => {\n const dispatch = useDispatch();\n\n return {\n save: () => dispatch(addRepeatableAttributeSet(form)),\n cancel: (object: FormObjectModel) =>\n dispatch(cancelRepeatableAttributeSet(form, object)),\n remove: (object: FormObjectModel) =>\n dispatch(removeRepeatableAttributeSet(form, object)),\n };\n};\n"],"file":"useForm.js"}
1
+ {"version":3,"sources":["../../src/hooks/useForm.js"],"names":["useForm","href","formHref","Href","addParameter","form","method","HTTP_METHODS","POST","targetModel","FormModel","removeOnUnmount","model","useFormNavigation","dispatch","previous","cancel","submit","connectKey","selfhref","data","formdata","updateModel","remove","showFormNotificationAction","showFormNotification","useAttributeUpdate","object","attribute","value","options","useAttributeValidate","useAttributeSet","save"],"mappings":";;;;;;;;;AACA;;AAEA;;AAEA;;AAEA;;AACA;;AAEA;;AAWA;;AA6BA;AACA;AACA;AACO,IAAMA,OAAO,GAAG,SAAVA,OAAU,CAACC,IAAD,EAAqC;AAC1D,MAAMC,QAAQ,GAAG,IAAIC,aAAJ,CAASF,IAAT,CAAjB;;AAEA,MAAI,CAAC,2BAAW,oBAAX,CAAL,EAAuC;AACrCC,IAAAA,QAAQ,CAACE,YAAT,CAAsB,QAAtB,EAAgC,OAAhC;AACD;;AAED,MAAMC,IAAI,GAAG,gCAAa,MAAb,EAAqBH,QAArB,EAA+B;AAC1CI,IAAAA,MAAM,EAAEC,wBAAaC,IADqB;AAE1CC,IAAAA,WAAW,EAAEC,kBAF6B;AAG1CC,IAAAA,eAAe,EAAE;AAHyB,GAA/B,CAAb;;AAMA,MAAIN,IAAJ,aAAIA,IAAJ,eAAIA,IAAI,CAAEO,KAAV,EAAiB;AACf,WAAOP,IAAI,CAACO,KAAZ;AACD;AACF,CAhBM;AAkBP;AACA;AACA;;;;;AACO,IAAMC,iBAAiB,GAAG,SAApBA,iBAAoB,GAA0B;AACzD,MAAMC,QAAQ,GAAG,8BAAjB;;AAEA,MAAMC,QAAQ,GAA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B,MAA1B,EAAkCC,SAAlC,EAA6CC,KAA7C,EAAoDC,OAApD,CAAD,CAJN;AAAA,GAAP;AAKD,CAXM;AAaP;AACA;AACA;;;;;AACO,IAAMC,oBAAoB,GAAG,SAAvBA,oBAAuB,CAAC1B,IAAD,EAA0C;AAC5E,MAAMS,QAAQ,GAAG,8BAAjB;AAEA,SAAO;AAAA,WAAMA,QAAQ,CAAC,oCAAsBT,IAAtB,CAAD,CAAd;AAAA,GAAP;AACD,CAJM;AAMP;AACA;AACA;;;;;AACO,IAAM2B,eAAe,GAAG,SAAlBA,eAAkB,CAAC3B,IAAD,EAAuC;AACpE,MAAMS,QAAQ,GAAG,8BAAjB;AAEA,SAAO;AACLmB,IAAAA,IAAI,EAAE;AAAA,aAAMnB,QAAQ,CAAC,wCAA0BT,IAA1B,CAAD,CAAd;AAAA,KADD;AAELW,IAAAA,MAAM,EAAE,gBAACW,MAAD;AAAA,aACNb,QAAQ,CAAC,2CAA6BT,IAA7B,EAAmCsB,MAAnC,CAAD,CADF;AAAA,KAFH;AAILJ,IAAAA,MAAM,EAAE,gBAACI,MAAD;AAAA,aACNb,QAAQ,CAAC,2CAA6BT,IAA7B,EAAmCsB,MAAnC,CAAD,CADF;AAAA;AAJH,GAAP;AAOD,CAVM","sourcesContent":["// @flow\nimport { useDispatch } from \"react-redux\";\n\nimport Href from \"../models/href/Href\";\n\nimport { getSetting, HTTP_METHODS } from \"../constants\";\n\nimport { loadModularUI, removeModelByKey } from \"../redux/_modularui\";\nimport { useModularUI } from \"./useModularUI\";\n\nimport {\n addRepeatableAttributeSet,\n cancelForm,\n cancelRepeatableAttributeSet,\n previousObject,\n removeRepeatableAttributeSet,\n showFormNotification,\n updateFormAttribute,\n validateFormAttribute,\n} from \"../redux/actions\";\n\nimport FormModel from \"../models/form/FormModel\";\n\nimport type { FormObjectModel, AttributeType } from \"../models\";\nimport type { UpdateFormOptions } from \"../redux/types\";\nimport type {\n RemoveModelByKeyAction,\n UpdateModelAction,\n} from \"../redux/_modularui\";\n\ntype FormNavigationHook = {\n previous: (form: FormModel) => UpdateModelAction,\n cancel: (form: FormModel) => void,\n submit: (form: FormModel) => void,\n showFormNotification: (form: FormModel) => void,\n remove: (form: FormModel) => RemoveModelByKeyAction,\n};\n\ntype AttributeSetHook = {\n save: () => UpdateModelAction,\n cancel: (object: FormObjectModel) => UpdateModelAction,\n remove: (object: FormObjectModel) => UpdateModelAction,\n};\n\ntype AttributeUpdateHook = (\n attribute: AttributeType,\n value: string,\n options: UpdateFormOptions\n) => void;\n\n/**\n * Load a form by href\n */\nexport const useForm = (href: string | Href): ?FormModel => {\n const formHref = new Href(href);\n\n if (!getSetting(\"ALWAYS_COMMIT_FORM\")) {\n formHref.addParameter(\"commit\", \"false\");\n }\n\n const form = useModularUI(\"form\", formHref, {\n method: HTTP_METHODS.POST,\n targetModel: FormModel,\n removeOnUnmount: true,\n });\n\n if (form?.model) {\n return form.model;\n }\n};\n\n/**\n * Form navigation methods\n */\nexport const useFormNavigation = (): FormNavigationHook => {\n const dispatch = useDispatch();\n\n const previous = (form: FormModel) => dispatch(previousObject(form));\n\n const cancel = (form: FormModel) => dispatch(cancelForm(form));\n\n const submit = (form: FormModel) =>\n dispatch(\n loadModularUI(form.connectKey, form.selfhref, {\n method: HTTP_METHODS.POST,\n data: form.formdata,\n updateModel: form,\n targetModel: FormModel,\n })\n );\n\n const remove = (form: FormModel) =>\n dispatch(removeModelByKey(form.connectKey));\n\n const showFormNotificationAction = (form: FormModel) =>\n dispatch(showFormNotification(form));\n\n return {\n previous,\n cancel,\n submit,\n remove,\n showFormNotification: showFormNotificationAction,\n };\n};\n\n/**\n * Update attributes of a form\n */\nexport const useAttributeUpdate = (\n form: FormModel,\n object: FormObjectModel\n): AttributeUpdateHook => {\n const dispatch = useDispatch();\n\n return (\n attribute: AttributeType,\n value: string,\n options: UpdateFormOptions\n ) => dispatch(updateFormAttribute(form, object, attribute, value, options));\n};\n\n/**\n * Validate attributes of a form\n */\nexport const useAttributeValidate = (form: FormModel): AttributeUpdateHook => {\n const dispatch = useDispatch();\n\n return () => dispatch(validateFormAttribute(form));\n};\n\n/**\n * Attributeset actions\n */\nexport const useAttributeSet = (form: FormModel): AttributeSetHook => {\n const dispatch = useDispatch();\n\n return {\n save: () => dispatch(addRepeatableAttributeSet(form)),\n cancel: (object: FormObjectModel) =>\n dispatch(cancelRepeatableAttributeSet(form, object)),\n remove: (object: FormObjectModel) =>\n dispatch(removeRepeatableAttributeSet(form, object)),\n };\n};\n"],"file":"useForm.js"}
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.updateFormAttribute = void 0;
6
+ exports.validateFormAttribute = exports.updateFormAttribute = void 0;
7
7
 
8
8
  var _actions = require("../_modularui/actions");
9
9
 
@@ -28,7 +28,7 @@ var updateFormAttribute = function updateFormAttribute(form, formObject, attribu
28
28
  return function (dispatch) {
29
29
  var newForm = form.clone();
30
30
 
31
- if (!options.validate) {
31
+ if (options.validate === undefined) {
32
32
  options.validate = true;
33
33
  }
34
34
 
@@ -61,6 +61,18 @@ var updateFormAttribute = function updateFormAttribute(form, formObject, attribu
61
61
  return dispatch((0, _actions.updateModel)(newForm));
62
62
  };
63
63
  };
64
+ /**
65
+ * Validate an attribute on a form
66
+ */
67
+
64
68
 
65
69
  exports.updateFormAttribute = updateFormAttribute;
70
+
71
+ var validateFormAttribute = function validateFormAttribute(form) {
72
+ return function (dispatch) {
73
+ return dispatch((0, _FormValidations.validateFormObject)(form));
74
+ };
75
+ };
76
+
77
+ exports.validateFormAttribute = validateFormAttribute;
66
78
  //# sourceMappingURL=FormAttributeSet.js.map
@@ -31,7 +31,7 @@ export const updateFormAttribute =
31
31
  (dispatch: Dispatch) => {
32
32
  const newForm = form.clone();
33
33
 
34
- if (!options.validate) {
34
+ if (options.validate === undefined) {
35
35
  options.validate = true;
36
36
  }
37
37
 
@@ -74,3 +74,12 @@ export const updateFormAttribute =
74
74
 
75
75
  return dispatch(updateModel(newForm));
76
76
  };
77
+
78
+ /**
79
+ * Validate an attribute on a form
80
+ */
81
+ export const validateFormAttribute =
82
+ (form: FormModel): ThunkAction =>
83
+ (dispatch: Dispatch) => {
84
+ return dispatch(validateFormObject(form));
85
+ };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/redux/actions/FormAttributeSet.js"],"names":["updateFormAttribute","form","formObject","attribute","inputvalue","options","autosubmit","autosave","forceUpdate","validate","dispatch","newForm","clone","currentFormObject","equals","updateAttribute","completedFormObjects","forEach","completeObject","isValid","autosubmitAction","isChanged","hasDynamicValidations"],"mappings":";;;;;;;AACA;;AAEA;;AAEA;;AACA;;AACA;;AAOA;AACA;AACA;AACO,IAAMA,mBAAmB,GAC9B,SADWA,mBACX,CACEC,IADF,EAEEC,UAFF,EAGEC,SAHF,EAIEC,UAJF;AAAA,MAKEC,OALF,uEAK+B;AAC3BC,IAAAA,UAAU,EAAE,KADe;AAE3BC,IAAAA,QAAQ,EAAE,KAFiB;AAG3BC,IAAAA,WAAW,EAAE,KAHc;AAI3BC,IAAAA,QAAQ,EAAE;AAJiB,GAL/B;AAAA,SAYA,UAACC,QAAD,EAAwB;AACtB,QAAMC,OAAO,GAAGV,IAAI,CAACW,KAAL,EAAhB;;AAEA,QAAI,CAACP,OAAO,CAACI,QAAb,EAAuB;AACrBJ,MAAAA,OAAO,CAACI,QAAR,GAAmB,IAAnB;AACD;;AAED,QACEE,OAAO,CAACE,iBAAR,IACAF,OAAO,CAACE,iBAAR,CAA0BC,MAA1B,CAAiCZ,UAAjC,CAFF,EAGE;AACAS,MAAAA,OAAO,CAACE,iBAAR,CAA0BE,eAA1B,CAA0CZ,SAA1C,EAAqDC,UAArD;AACD,KALD,MAKO;AACLO,MAAAA,OAAO,CAACK,oBAAR,CAA6BC,OAA7B,CAAqC,UAACC,cAAD,EAAoB;AACvD,YAAIA,cAAc,CAACJ,MAAf,CAAsBZ,UAAtB,CAAJ,EAAuC;AACrCgB,UAAAA,cAAc,CAACH,eAAf,CAA+BZ,SAA/B,EAA0CC,UAA1C;AACD;AACF,OAJD;AAKD;;AAED,QAAIC,OAAO,CAACC,UAAR,IAAsBK,OAAO,CAACQ,OAAlC,EAA2C;AACzC,UAAMC,gBAAgB,GAAG,0CACvBT,OADuB,EAEvBR,SAFuB,EAGvBE,OAAO,CAACG,WAHe,CAAzB;;AAKA,UAAIY,gBAAJ,EAAsB;AACpB,eAAOV,QAAQ,CAACU,gBAAD,CAAf;AACD;AACF;;AAED,QAAIf,OAAO,CAACE,QAAR,IAAoBI,OAAO,CAACQ,OAA5B,IAAuCR,OAAO,CAACU,SAAR,EAA3C,EAAgE;AAC9DX,MAAAA,QAAQ,CAAC,sCAAmBC,OAAnB,CAAD,CAAR;AACD;;AAED,QACEA,OAAO,CAACE,iBAAR,IACAR,OAAO,CAACI,QADR,IAEAE,OAAO,CAACE,iBAAR,CAA0BS,qBAF1B,IAGA,0BAAW,+BAAX,CAJF,EAKE;AACAZ,MAAAA,QAAQ,CAAC,yCAAmBC,OAAnB,CAAD,CAAR;AACD;;AAED,WAAOD,QAAQ,CAAC,0BAAYC,OAAZ,CAAD,CAAf;AACD,GAzDD;AAAA,CADK","sourcesContent":["// @flow\nimport { updateModel } from \"../_modularui/actions\";\n\nimport { getSetting } from \"../../constants/Settings\";\n\nimport { validateFormObject } from \"./FormValidations\";\nimport { autosaveFormObject } from \"./FormAutosave\";\nimport { autosubmitFormObject } from \"./FormAutosubmit\";\n\nimport type { Dispatch, ThunkAction, UpdateFormOptions } from \"../types\";\nimport type { AttributeType } from \"../../models/types\";\nimport type FormModel from \"../../models/form/FormModel\";\nimport type FormObjectModel from \"../../models/form/FormObjectModel\";\n\n/**\n * Update an attribute on a form\n */\nexport const updateFormAttribute =\n (\n form: FormModel,\n formObject: FormObjectModel,\n attribute: AttributeType,\n inputvalue: string,\n options: UpdateFormOptions = {\n autosubmit: false,\n autosave: false,\n forceUpdate: false,\n validate: true,\n }\n ): ThunkAction =>\n (dispatch: Dispatch) => {\n const newForm = form.clone();\n\n if (!options.validate) {\n options.validate = true;\n }\n\n if (\n newForm.currentFormObject &&\n newForm.currentFormObject.equals(formObject)\n ) {\n newForm.currentFormObject.updateAttribute(attribute, inputvalue);\n } else {\n newForm.completedFormObjects.forEach((completeObject) => {\n if (completeObject.equals(formObject)) {\n completeObject.updateAttribute(attribute, inputvalue);\n }\n });\n }\n\n if (options.autosubmit && newForm.isValid) {\n const autosubmitAction = autosubmitFormObject(\n newForm,\n attribute,\n options.forceUpdate\n );\n if (autosubmitAction) {\n return dispatch(autosubmitAction);\n }\n }\n\n if (options.autosave && newForm.isValid && newForm.isChanged()) {\n dispatch(autosaveFormObject(newForm));\n }\n\n if (\n newForm.currentFormObject &&\n options.validate &&\n newForm.currentFormObject.hasDynamicValidations &&\n getSetting(\"USE_INSTANT_SERVER_VALIDATION\")\n ) {\n dispatch(validateFormObject(newForm));\n }\n\n return dispatch(updateModel(newForm));\n };\n"],"file":"FormAttributeSet.js"}
1
+ {"version":3,"sources":["../../../src/redux/actions/FormAttributeSet.js"],"names":["updateFormAttribute","form","formObject","attribute","inputvalue","options","autosubmit","autosave","forceUpdate","validate","dispatch","newForm","clone","undefined","currentFormObject","equals","updateAttribute","completedFormObjects","forEach","completeObject","isValid","autosubmitAction","isChanged","hasDynamicValidations","validateFormAttribute"],"mappings":";;;;;;;AACA;;AAEA;;AAEA;;AACA;;AACA;;AAOA;AACA;AACA;AACO,IAAMA,mBAAmB,GAC9B,SADWA,mBACX,CACEC,IADF,EAEEC,UAFF,EAGEC,SAHF,EAIEC,UAJF;AAAA,MAKEC,OALF,uEAK+B;AAC3BC,IAAAA,UAAU,EAAE,KADe;AAE3BC,IAAAA,QAAQ,EAAE,KAFiB;AAG3BC,IAAAA,WAAW,EAAE,KAHc;AAI3BC,IAAAA,QAAQ,EAAE;AAJiB,GAL/B;AAAA,SAYA,UAACC,QAAD,EAAwB;AACtB,QAAMC,OAAO,GAAGV,IAAI,CAACW,KAAL,EAA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,qBAAqB,GAChC,SADWA,qBACX,CAACvB,IAAD;AAAA,SACA,UAACS,QAAD,EAAwB;AACtB,WAAOA,QAAQ,CAAC,yCAAmBT,IAAnB,CAAD,CAAf;AACD,GAHD;AAAA,CADK","sourcesContent":["// @flow\nimport { updateModel } from \"../_modularui/actions\";\n\nimport { getSetting } from \"../../constants/Settings\";\n\nimport { validateFormObject } from \"./FormValidations\";\nimport { autosaveFormObject } from \"./FormAutosave\";\nimport { autosubmitFormObject } from \"./FormAutosubmit\";\n\nimport type { Dispatch, ThunkAction, UpdateFormOptions } from \"../types\";\nimport type { AttributeType } from \"../../models/types\";\nimport type FormModel from \"../../models/form/FormModel\";\nimport type FormObjectModel from \"../../models/form/FormObjectModel\";\n\n/**\n * Update an attribute on a form\n */\nexport const updateFormAttribute =\n (\n form: FormModel,\n formObject: FormObjectModel,\n attribute: AttributeType,\n inputvalue: string,\n options: UpdateFormOptions = {\n autosubmit: false,\n autosave: false,\n forceUpdate: false,\n validate: true,\n }\n ): ThunkAction =>\n (dispatch: Dispatch) => {\n const newForm = form.clone();\n\n if (options.validate === undefined) {\n options.validate = true;\n }\n\n if (\n newForm.currentFormObject &&\n newForm.currentFormObject.equals(formObject)\n ) {\n newForm.currentFormObject.updateAttribute(attribute, inputvalue);\n } else {\n newForm.completedFormObjects.forEach((completeObject) => {\n if (completeObject.equals(formObject)) {\n completeObject.updateAttribute(attribute, inputvalue);\n }\n });\n }\n\n if (options.autosubmit && newForm.isValid) {\n const autosubmitAction = autosubmitFormObject(\n newForm,\n attribute,\n options.forceUpdate\n );\n if (autosubmitAction) {\n return dispatch(autosubmitAction);\n }\n }\n\n if (options.autosave && newForm.isValid && newForm.isChanged()) {\n dispatch(autosaveFormObject(newForm));\n }\n\n if (\n newForm.currentFormObject &&\n options.validate &&\n newForm.currentFormObject.hasDynamicValidations &&\n getSetting(\"USE_INSTANT_SERVER_VALIDATION\")\n ) {\n dispatch(validateFormObject(newForm));\n }\n\n return dispatch(updateModel(newForm));\n };\n\n/**\n * Validate an attribute on a form\n */\nexport const validateFormAttribute =\n (form: FormModel): ThunkAction =>\n (dispatch: Dispatch) => {\n return dispatch(validateFormObject(form));\n };\n"],"file":"FormAttributeSet.js"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@beinformed/ui",
3
- "version": "1.17.1",
3
+ "version": "1.17.2",
4
4
  "description": "Toolbox for be informed javascript layouts",
5
5
  "license": "SEE LICENSE IN LICENSE.md",
6
6
  "bugs": "http://support.beinformed.com",
@@ -16,6 +16,7 @@ import {
16
16
  removeRepeatableAttributeSet,
17
17
  showFormNotification,
18
18
  updateFormAttribute,
19
+ validateFormAttribute,
19
20
  } from "../redux/actions";
20
21
 
21
22
  import FormModel from "../models/form/FormModel";
@@ -119,6 +120,15 @@ export const useAttributeUpdate = (
119
120
  ) => dispatch(updateFormAttribute(form, object, attribute, value, options));
120
121
  };
121
122
 
123
+ /**
124
+ * Validate attributes of a form
125
+ */
126
+ export const useAttributeValidate = (form: FormModel): AttributeUpdateHook => {
127
+ const dispatch = useDispatch();
128
+
129
+ return () => dispatch(validateFormAttribute(form));
130
+ };
131
+
122
132
  /**
123
133
  * Attributeset actions
124
134
  */
@@ -31,7 +31,7 @@ export const updateFormAttribute =
31
31
  (dispatch: Dispatch) => {
32
32
  const newForm = form.clone();
33
33
 
34
- if (!options.validate) {
34
+ if (options.validate === undefined) {
35
35
  options.validate = true;
36
36
  }
37
37
 
@@ -74,3 +74,12 @@ export const updateFormAttribute =
74
74
 
75
75
  return dispatch(updateModel(newForm));
76
76
  };
77
+
78
+ /**
79
+ * Validate an attribute on a form
80
+ */
81
+ export const validateFormAttribute =
82
+ (form: FormModel): ThunkAction =>
83
+ (dispatch: Dispatch) => {
84
+ return dispatch(validateFormObject(form));
85
+ };