@mobx-ecosystem/mobx-form
Advanced tools
Comparing version 2.10.29 to 2.10.30
@@ -1,1 +0,1 @@ | ||
import{isEqual as e}from"lodash";import{makeAutoObservable as i}from"mobx";import t from"mitt";class r{constructor(e,r){Object.defineProperty(this,"_isListenerWorks",{enumerable:!0,configurable:!0,writable:!0,value:!0}),Object.defineProperty(this,"eventBus",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"validate",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_serviceType",{enumerable:!0,configurable:!0,writable:!0,value:"field-service"}),Object.defineProperty(this,"_initValue",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_value",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_error",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_disabled",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_isBlurred",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"options",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"createListener",{enumerable:!0,configurable:!0,writable:!0,value:()=>{this._isListenerWorks=!0,this.eventBus=t()}}),Object.defineProperty(this,"pauseListener",{enumerable:!0,configurable:!0,writable:!0,value:()=>{this._isListenerWorks=!1}}),Object.defineProperty(this,"resumeListener",{enumerable:!0,configurable:!0,writable:!0,value:()=>{this._isListenerWorks=!0}}),Object.defineProperty(this,"destroyListener",{enumerable:!0,configurable:!0,writable:!0,value:()=>{this.eventBus=void 0}}),Object.defineProperty(this,"onChange",{enumerable:!0,configurable:!0,writable:!0,value:(e,i)=>{var t;this.value=i,null===(t=this.validate)||void 0===t||t.call(this)}}),Object.defineProperty(this,"onBlur",{enumerable:!0,configurable:!0,writable:!0,value:e=>{var i;this.isBlurred=!0,null===(i=this.validate)||void 0===i||i.call(this)}}),Object.defineProperty(this,"reset",{enumerable:!0,configurable:!0,writable:!0,value:()=>{this.value=this.initValue,this.isBlurred=!1}}),Object.defineProperty(this,"setAsInit",{enumerable:!0,configurable:!0,writable:!0,value:()=>{this.initValue=this.value,this.isBlurred=!1}}),Object.defineProperty(this,"touch",{enumerable:!0,configurable:!0,writable:!0,value:()=>{this.isBlurred=!0}}),i(this),this.initValue=e,this.options=r}get initValue(){return this._initValue}set initValue(e){var i;this._initValue=e,this._value=e,null===(i=this.validate)||void 0===i||i.call(this)}get value(){return this._value}set value(e){var i;const t=this._value;this._value=e,t!==e&&this._isListenerWorks&&(null===(i=this.eventBus)||void 0===i||i.emit("ON_CHANGE",e))}get error(){return this._error}set error(e){this._error=e}get disabled(){return this._disabled}set disabled(e){this._disabled=e}get isValid(){return!this._error}get isInit(){return null!==(i=this.value)&&"object"==typeof i?e(this.value,this._initValue):this._value===this._initValue;var i}get isBlurred(){return this._isBlurred}set isBlurred(e){this._isBlurred=e}get isTouched(){return!this.isInit||this.isBlurred}get props(){var e;let i={value:this.value,error:this.error,disabled:this.disabled};return(null===(e=this.options)||void 0===e?void 0:e.onError)&&(i=Object.assign(Object.assign({},i),{onError:e=>{this.error=this.error||(null==e?void 0:e.toString())}})),Object.assign(Object.assign({},i),{onChange:this.onChange,onBlur:this.onBlur})}}function l(e,i,t,r){return new(t||(t=Promise))((function(l,s){function a(e){try{u(r.next(e))}catch(e){s(e)}}function n(e){try{u(r.throw(e))}catch(e){s(e)}}function u(e){var i;e.done?l(e.value):(i=e.value,i instanceof t?i:new t((function(e){e(i)}))).then(a,n)}u((r=r.apply(e,i||[])).next())}))}let s,a;const n=e=>{s=e.validation.validate,a=e.validation.preSubmitValidationError},u=()=>{if(!s||!a)throw new Error("You must define configureForm to configure mobx-form")};class o{constructor(e){Object.defineProperty(this,"_touched",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_disabled",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_error",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_initValue",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_value",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"setTouched",{enumerable:!0,configurable:!0,writable:!0,value:e=>{this._touched=e}}),Object.defineProperty(this,"add",{enumerable:!0,configurable:!0,writable:!0,value:e=>{var i;this.value.push(e),this.setTouched(!0),null===(i=this.validate)||void 0===i||i.call(this,"only-touched")}}),Object.defineProperty(this,"removeByIndex",{enumerable:!0,configurable:!0,writable:!0,value:e=>{var i;this.value.splice(e,1),this.setTouched(!0),null===(i=this.validate)||void 0===i||i.call(this,"only-touched")}}),Object.defineProperty(this,"reset",{enumerable:!0,configurable:!0,writable:!0,value:()=>{this._value=this.initValue.slice(0),this._value.forEach((e=>e.formService.reset())),this.setTouched(!1)}}),Object.defineProperty(this,"setAsInit",{enumerable:!0,configurable:!0,writable:!0,value:()=>{this.initValue=this.value,this._value.forEach((e=>e.formService.setValuesAsInit())),this.setTouched(!1)}}),Object.defineProperty(this,"getValues",{enumerable:!0,configurable:!0,writable:!0,value:()=>this.value.map((e=>e.formService.getValues()))}),Object.defineProperty(this,"touch",{enumerable:!0,configurable:!0,writable:!0,value:()=>{this.value.forEach((e=>e.formService.touch())),this.setTouched(!0)}}),Object.defineProperty(this,"validate",{enumerable:!0,configurable:!0,writable:!0,value:(e="everything")=>Promise.all(this.value.map((i=>i.formService.validate(e))))}),i(this),this.initValue=e||[]}get initValue(){return this._initValue}set initValue(e){var i;this._initValue=e,this._value=e.slice(0),this.setTouched(!1),null===(i=this.validate)||void 0===i||i.call(this,"only-touched")}get value(){return this._value}set value(e){this._value=e,this.setTouched(!0)}get disabled(){return this._disabled}set disabled(e){this._disabled=e,e?this.value.forEach((e=>e.formService.disable())):this.value.forEach((e=>e.formService.enable()))}get error(){return this._error}set error(e){this._error=e}get isValid(){return!this._error&&this.value.every((e=>e.formService.isValid))}get isTouched(){return this._touched||this.value.some((e=>e.formService.isTouched))}get isInit(){return!this.isTouched}get hasItems(){return Boolean(this.value.length)}}class h{constructor(e){Object.defineProperty(this,"field",{enumerable:!0,configurable:!0,writable:!0,value:new r(null)}),Object.defineProperty(this,"inputField",{enumerable:!0,configurable:!0,writable:!0,value:new r("")}),Object.defineProperty(this,"setValue",{enumerable:!0,configurable:!0,writable:!0,value:(e,{inputValue:i="",withNotification:t=!0,withBlur:r=!0})=>{var l,s,a,n;if(t?(this.field.value=e,this.inputField.value=i):(this.field.pauseListener(),this.inputField.pauseListener(),this.field.value=e,this.inputField.value=i,null===(s=(l=this.field).validate)||void 0===s||s.call(l),null===(n=(a=this.inputField).validate)||void 0===n||n.call(a),this.field.resumeListener(),this.inputField.resumeListener()),r)return this.field.isBlurred=!0}}),Object.defineProperty(this,"reset",{enumerable:!0,configurable:!0,writable:!0,value:()=>{this.field.reset()}}),Object.defineProperty(this,"setAsInit",{enumerable:!0,configurable:!0,writable:!0,value:()=>{this.field.setAsInit()}}),Object.defineProperty(this,"onInputChange",{enumerable:!0,configurable:!0,writable:!0,value:(e,i)=>{this.inputField.value=i}}),Object.defineProperty(this,"touch",{enumerable:!0,configurable:!0,writable:!0,value:()=>{this.field.touch()}}),i(this),this.field.initValue=e}get validate(){return this.field.validate}set validate(e){this.field.validate=e}get value(){return this.field.value}set value(e){this.field.value=e}get error(){return this.field.error}set error(e){this.field.error=e}get disabled(){return this.field.disabled}set disabled(e){this.field.disabled=e}get isValid(){return this.field.isValid}get isInit(){return this.field.isInit}set initValue(e){this.field.initValue=e}get isTouched(){return this.field.isTouched}get initValue(){return this.field.initValue}get props(){return Object.assign(Object.assign({},this.field.props),{inputValue:this.inputField.value,onInputChange:this.onInputChange})}}class d{constructor(e,t){Object.defineProperty(this,"fields",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"validationSchema",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"onSubmit",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"setOnSubmit",{enumerable:!0,configurable:!0,writable:!0,value:e=>{this.onSubmit=e}}),Object.defineProperty(this,"submit",{enumerable:!0,configurable:!0,writable:!0,value:()=>l(this,void 0,void 0,(function*(){var e;if(yield this.validate("everything"),this.canBeSubmitted)return null===(e=this.onSubmit)||void 0===e?void 0:e.call(this);null==a||a()}))}),Object.defineProperty(this,"validate",{enumerable:!0,configurable:!0,writable:!0,value:(e="only-touched")=>l(this,void 0,void 0,(function*(){const i=this.getValues();yield this.bypassFields(this.fields,(e=>l(this,void 0,void 0,(function*(){var i;if(e instanceof o)return yield null===(i=e.validate)||void 0===i?void 0:i.call(e)}))));const t=yield null==s?void 0:s(i,this.validationSchema);t&&0!=Object.keys(t||[]).length?this.setErrors(t,e):this.resetErrors()}))}),Object.defineProperty(this,"setValidationSchema",{enumerable:!0,configurable:!0,writable:!0,value:e=>{this.validationSchema=e,this.setValidationToFields()}}),Object.defineProperty(this,"getValues",{enumerable:!0,configurable:!0,writable:!0,value:()=>{const e={};for(const i of this.keys)e[i]=this.getValue(this.fields[i]);return e}}),Object.defineProperty(this,"getValue",{enumerable:!0,configurable:!0,writable:!0,value:e=>{if(e instanceof r||e instanceof o||e instanceof h)return null==e?void 0:e.value;if("object"==typeof e){const i={};for(const t of Object.keys(e))i[t]=this.getValue(null==e?void 0:e[t]);return i}return e}}),Object.defineProperty(this,"setFieldsByThis",{enumerable:!0,configurable:!0,writable:!0,value:e=>{const i={};Object.keys(e).forEach((t=>{(e[t]&&e[t]instanceof r||e[t]instanceof o||e[t]instanceof h)&&(i[t]=e[t])})),this.fields=i,this.setValidationToFields()}}),Object.defineProperty(this,"bypassFields",{enumerable:!0,configurable:!0,writable:!0,value:(e,i,t)=>e instanceof r||e instanceof o||e instanceof h?i(e,t):"object"==typeof e?Object.keys(e||{}).map((r=>this.bypassFields(null==e?void 0:e[r],i,null==t?void 0:t[r]))):void 0}),Object.defineProperty(this,"setValidationToFields",{enumerable:!0,configurable:!0,writable:!0,value:()=>{this.bypassFields(this.fields,(e=>{e instanceof o||(e.validate=this.validate)}))}}),Object.defineProperty(this,"setInitValues",{enumerable:!0,configurable:!0,writable:!0,value:e=>{this.bypassFields(this.fields,((e,i)=>e.initValue=i),e)}}),Object.defineProperty(this,"setValues",{enumerable:!0,configurable:!0,writable:!0,value:e=>{this.bypassFields(this.fields,((e,i)=>e.value=i),e)}}),Object.defineProperty(this,"resetErrors",{enumerable:!0,configurable:!0,writable:!0,value:()=>{this.bypassFields(this.fields,(e=>e.error=void 0))}}),Object.defineProperty(this,"setValuesAsInit",{enumerable:!0,configurable:!0,writable:!0,value:()=>{this.bypassFields(this.fields,(e=>{e.setAsInit()}))}}),Object.defineProperty(this,"reset",{enumerable:!0,configurable:!0,writable:!0,value:()=>{this.bypassFields(this.fields,(e=>e.reset())),this.validate()}}),Object.defineProperty(this,"disable",{enumerable:!0,configurable:!0,writable:!0,value:()=>{this.bypassFields(this.fields,(e=>e.disabled=!0))}}),Object.defineProperty(this,"enable",{enumerable:!0,configurable:!0,writable:!0,value:()=>{this.bypassFields(this.fields,(e=>e.disabled=!1))}}),Object.defineProperty(this,"touch",{enumerable:!0,configurable:!0,writable:!0,value:()=>{this.bypassFields(this.fields,(e=>e.touch()))}}),u(),i(this),this.fields=e,this.validationSchema=t,this.setValidationToFields()}get keys(){return Object.keys(this.fields)}get isValid(){let e=!0;return this.bypassFields(this.fields,(i=>{i.isValid||(e=!1)})),e}get isTouched(){let e=!1;return this.bypassFields(this.fields,(i=>{i.isTouched&&(e=!0)})),e}get canBeSubmitted(){return this.isTouched&&this.isValid}get disabled(){let e=!0;return this.bypassFields(this.fields,(i=>{i.disabled||(e=!1)})),e}setErrors(e,i="only-touched"){this.bypassFields(this.fields,((e,t)=>{(e.isTouched||"everything"===i)&&(e.error=t)}),e)}}export{h as AutocompleteFieldService,o as CombinedFormFieldService,r as FieldService,d as FormService,u as _checkConfiguration,n as configureForm,a as preSubmitValidationError,s as validate}; | ||
import{isEqual as e}from"lodash";import{makeAutoObservable as i}from"mobx";import t from"mitt";class r{constructor(e,r){Object.defineProperty(this,"_isListenerWorks",{enumerable:!0,configurable:!0,writable:!0,value:!0}),Object.defineProperty(this,"eventBus",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"validate",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_serviceType",{enumerable:!0,configurable:!0,writable:!0,value:"field-service"}),Object.defineProperty(this,"_initValue",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_value",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_error",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_disabled",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_isBlurred",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"options",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"createListener",{enumerable:!0,configurable:!0,writable:!0,value:()=>{this._isListenerWorks=!0,this.eventBus=t()}}),Object.defineProperty(this,"pauseListener",{enumerable:!0,configurable:!0,writable:!0,value:()=>{this._isListenerWorks=!1}}),Object.defineProperty(this,"resumeListener",{enumerable:!0,configurable:!0,writable:!0,value:()=>{this._isListenerWorks=!0}}),Object.defineProperty(this,"destroyListener",{enumerable:!0,configurable:!0,writable:!0,value:()=>{this.eventBus=void 0}}),Object.defineProperty(this,"onChange",{enumerable:!0,configurable:!0,writable:!0,value:(e,i)=>{var t;this.value=i,null===(t=this.validate)||void 0===t||t.call(this)}}),Object.defineProperty(this,"onBlur",{enumerable:!0,configurable:!0,writable:!0,value:e=>{var i;this.isBlurred=!0,null===(i=this.validate)||void 0===i||i.call(this)}}),Object.defineProperty(this,"reset",{enumerable:!0,configurable:!0,writable:!0,value:()=>{this.value=this.initValue,this.isBlurred=!1}}),Object.defineProperty(this,"setAsInit",{enumerable:!0,configurable:!0,writable:!0,value:()=>{this.initValue=this.value,this.isBlurred=!1}}),Object.defineProperty(this,"touch",{enumerable:!0,configurable:!0,writable:!0,value:()=>{this.isBlurred=!0}}),i(this),this.initValue=e,this.options=r}get initValue(){return this._initValue}set initValue(e){var i;this._initValue=e,this._value=e,null===(i=this.validate)||void 0===i||i.call(this)}get value(){return this._value}set value(e){var i;const t=this._value;this._value=e,t!==e&&this._isListenerWorks&&(null===(i=this.eventBus)||void 0===i||i.emit("ON_CHANGE",e))}get error(){return this._error}set error(e){this._error=e}get disabled(){return this._disabled}set disabled(e){this._disabled=e}get isValid(){return!this._error}get isInit(){return null!==(i=this.value)&&"object"==typeof i?e(this.value,this._initValue):this._value===this._initValue;var i}get isBlurred(){return this._isBlurred}set isBlurred(e){this._isBlurred=e}get isTouched(){return!this.isInit||this.isBlurred}get props(){var e;let i={value:this.value,error:this.error,disabled:this.disabled};return(null===(e=this.options)||void 0===e?void 0:e.onError)&&(i=Object.assign(Object.assign({},i),{onError:e=>{this.error=this.error||(null==e?void 0:e.toString())}})),Object.assign(Object.assign({},i),{onChange:this.onChange,onBlur:this.onBlur})}}function l(e,i,t,r){return new(t||(t=Promise))((function(l,s){function a(e){try{u(r.next(e))}catch(e){s(e)}}function n(e){try{u(r.throw(e))}catch(e){s(e)}}function u(e){var i;e.done?l(e.value):(i=e.value,i instanceof t?i:new t((function(e){e(i)}))).then(a,n)}u((r=r.apply(e,i||[])).next())}))}let s,a;const n=e=>{s=e.validation.validate,a=e.validation.preSubmitValidationError},u=()=>{if(!s||!a)throw new Error("You must define configureForm to configure mobx-form")};class o{constructor(e){Object.defineProperty(this,"_touched",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_disabled",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_error",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_initValue",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_value",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"setTouched",{enumerable:!0,configurable:!0,writable:!0,value:e=>{this._touched=e}}),Object.defineProperty(this,"add",{enumerable:!0,configurable:!0,writable:!0,value:e=>{var i;this.value.push(e),this.setTouched(!0),null===(i=this.validate)||void 0===i||i.call(this,"only-touched")}}),Object.defineProperty(this,"removeByIndex",{enumerable:!0,configurable:!0,writable:!0,value:e=>{var i;this.value.splice(e,1),this.setTouched(!0),null===(i=this.validate)||void 0===i||i.call(this,"only-touched")}}),Object.defineProperty(this,"reset",{enumerable:!0,configurable:!0,writable:!0,value:()=>{this._value=this.initValue.slice(0),this._value.forEach((e=>e.formService.reset())),this.setTouched(!1)}}),Object.defineProperty(this,"setAsInit",{enumerable:!0,configurable:!0,writable:!0,value:()=>{this.initValue=this.value,this._value.forEach((e=>e.formService.setValuesAsInit())),this.setTouched(!1)}}),Object.defineProperty(this,"getValues",{enumerable:!0,configurable:!0,writable:!0,value:()=>this.value.map((e=>e.formService.getValues()))}),Object.defineProperty(this,"touch",{enumerable:!0,configurable:!0,writable:!0,value:()=>{this.value.forEach((e=>e.formService.touch())),this.setTouched(!0)}}),Object.defineProperty(this,"validate",{enumerable:!0,configurable:!0,writable:!0,value:(e="everything")=>Promise.all(this.value.map((i=>i.formService.validate(e))))}),i(this),this.initValue=e||[]}get initValue(){return this._initValue}set initValue(e){var i;this._initValue=e,this._value=e.slice(0),this.setTouched(!1),null===(i=this.validate)||void 0===i||i.call(this,"only-touched")}get value(){return this._value}set value(e){this._value=e,this.setTouched(!0)}get disabled(){return this._disabled}set disabled(e){this._disabled=e,e?this.value.forEach((e=>e.formService.disable())):this.value.forEach((e=>e.formService.enable()))}get error(){return this._error}set error(e){this._error=e}get isValid(){return!this._error&&this.value.every((e=>e.formService.isValid))}get isTouched(){return this._touched||this.value.some((e=>e.formService.isTouched))}get isInit(){return!this.isTouched}get hasItems(){return Boolean(this.value.length)}}class h{constructor(e){Object.defineProperty(this,"field",{enumerable:!0,configurable:!0,writable:!0,value:new r(null)}),Object.defineProperty(this,"inputField",{enumerable:!0,configurable:!0,writable:!0,value:new r("")}),Object.defineProperty(this,"setValue",{enumerable:!0,configurable:!0,writable:!0,value:(e,{inputValue:i="",withNotification:t=!0,withBlur:r=!0})=>{var l,s,a,n;if(t?(this.field.value=e,this.inputField.value=i):(this.field.pauseListener(),this.inputField.pauseListener(),this.field.value=e,this.inputField.value=i,null===(s=(l=this.field).validate)||void 0===s||s.call(l),null===(n=(a=this.inputField).validate)||void 0===n||n.call(a),this.field.resumeListener(),this.inputField.resumeListener()),r)return this.field.isBlurred=!0}}),Object.defineProperty(this,"reset",{enumerable:!0,configurable:!0,writable:!0,value:()=>{this.field.reset()}}),Object.defineProperty(this,"setAsInit",{enumerable:!0,configurable:!0,writable:!0,value:()=>{this.field.setAsInit()}}),Object.defineProperty(this,"onInputChange",{enumerable:!0,configurable:!0,writable:!0,value:(e,i)=>{this.inputField.value=i}}),Object.defineProperty(this,"touch",{enumerable:!0,configurable:!0,writable:!0,value:()=>{this.field.touch()}}),i(this),this.field.initValue=e}get validate(){return this.field.validate}set validate(e){this.field.validate=e}get value(){return this.field.value}set value(e){this.field.value=e}get error(){return this.field.error}set error(e){this.field.error=e}get disabled(){return this.field.disabled}set disabled(e){this.field.disabled=e}get isValid(){return this.field.isValid}get isInit(){return this.field.isInit}set initValue(e){this.field.initValue=e}get isTouched(){return this.field.isTouched}get initValue(){return this.field.initValue}get props(){return Object.assign(Object.assign({},this.field.props),{inputValue:this.inputField.value,onInputChange:this.onInputChange})}}class d{constructor(e,t){Object.defineProperty(this,"fields",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"validationSchema",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"onSubmit",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"setOnSubmit",{enumerable:!0,configurable:!0,writable:!0,value:e=>{this.onSubmit=e}}),Object.defineProperty(this,"submit",{enumerable:!0,configurable:!0,writable:!0,value:()=>l(this,void 0,void 0,(function*(){var e;if(yield this.validate("everything"),this.canBeSubmitted)return null===(e=this.onSubmit)||void 0===e?void 0:e.call(this);null==a||a()}))}),Object.defineProperty(this,"validate",{enumerable:!0,configurable:!0,writable:!0,value:(e="only-touched")=>l(this,void 0,void 0,(function*(){const i=this.getValues();yield this.bypassFields(this.fields,(e=>l(this,void 0,void 0,(function*(){var i;if(e instanceof o)return yield null===(i=e.validate)||void 0===i?void 0:i.call(e)}))));const t=yield null==s?void 0:s(i,this.validationSchema);t&&0!=Object.keys(t||[]).length?this.setErrors(t,e):this.resetErrors()}))}),Object.defineProperty(this,"setValidationSchema",{enumerable:!0,configurable:!0,writable:!0,value:e=>{this.validationSchema=e,this.setValidationToFields()}}),Object.defineProperty(this,"getValues",{enumerable:!0,configurable:!0,writable:!0,value:()=>{const e={};for(const i of this.keys)e[i]=this.getValue(this.fields[i]);return e}}),Object.defineProperty(this,"getValue",{enumerable:!0,configurable:!0,writable:!0,value:e=>{if(e instanceof r||e instanceof o||e instanceof h)return null==e?void 0:e.value;if("object"==typeof e){const i={};for(const t of Object.keys(e))i[t]=this.getValue(null==e?void 0:e[t]);return i}return e}}),Object.defineProperty(this,"setFieldsByThis",{enumerable:!0,configurable:!0,writable:!0,value:e=>{const i={};Object.keys(e).forEach((t=>{(e[t]&&e[t]instanceof r||e[t]instanceof o||e[t]instanceof h)&&(i[t]=e[t])})),this.fields=i,this.setValidationToFields()}}),Object.defineProperty(this,"bypassFields",{enumerable:!0,configurable:!0,writable:!0,value:(e,i,t)=>e instanceof r||e instanceof o||e instanceof h?i(e,t):"object"==typeof e?Promise.all(Object.keys(e||{}).map((r=>this.bypassFields(null==e?void 0:e[r],i,null==t?void 0:t[r])))):void 0}),Object.defineProperty(this,"setValidationToFields",{enumerable:!0,configurable:!0,writable:!0,value:()=>{this.bypassFields(this.fields,(e=>{e instanceof o||(e.validate=this.validate)}))}}),Object.defineProperty(this,"setInitValues",{enumerable:!0,configurable:!0,writable:!0,value:e=>{this.bypassFields(this.fields,((e,i)=>e.initValue=i),e)}}),Object.defineProperty(this,"setValues",{enumerable:!0,configurable:!0,writable:!0,value:e=>{this.bypassFields(this.fields,((e,i)=>e.value=i),e)}}),Object.defineProperty(this,"resetErrors",{enumerable:!0,configurable:!0,writable:!0,value:()=>{this.bypassFields(this.fields,(e=>e.error=void 0))}}),Object.defineProperty(this,"setValuesAsInit",{enumerable:!0,configurable:!0,writable:!0,value:()=>{this.bypassFields(this.fields,(e=>{e.setAsInit()}))}}),Object.defineProperty(this,"reset",{enumerable:!0,configurable:!0,writable:!0,value:()=>{this.bypassFields(this.fields,(e=>e.reset())),this.validate()}}),Object.defineProperty(this,"disable",{enumerable:!0,configurable:!0,writable:!0,value:()=>{this.bypassFields(this.fields,(e=>e.disabled=!0))}}),Object.defineProperty(this,"enable",{enumerable:!0,configurable:!0,writable:!0,value:()=>{this.bypassFields(this.fields,(e=>e.disabled=!1))}}),Object.defineProperty(this,"touch",{enumerable:!0,configurable:!0,writable:!0,value:()=>{this.bypassFields(this.fields,(e=>e.touch()))}}),u(),i(this),this.fields=e,this.validationSchema=t,this.setValidationToFields()}get keys(){return Object.keys(this.fields)}get isValid(){let e=!0;return this.bypassFields(this.fields,(i=>{i.isValid||(e=!1)})),e}get isTouched(){let e=!1;return this.bypassFields(this.fields,(i=>{i.isTouched&&(e=!0)})),e}get canBeSubmitted(){return this.isTouched&&this.isValid}get disabled(){let e=!0;return this.bypassFields(this.fields,(i=>{i.disabled||(e=!1)})),e}setErrors(e,i="only-touched"){this.bypassFields(this.fields,((e,t)=>{(e.isTouched||"everything"===i)&&(e.error=t)}),e)}}export{h as AutocompleteFieldService,o as CombinedFormFieldService,r as FieldService,d as FormService,u as _checkConfiguration,n as configureForm,a as preSubmitValidationError,s as validate}; |
@@ -5,3 +5,3 @@ { | ||
"private": false, | ||
"version": "2.10.29", | ||
"version": "2.10.30", | ||
"description": "provides the ability to use forms with validation in MobX stores", | ||
@@ -8,0 +8,0 @@ "main": "dist/index.js", |
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
24118