Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@mobx-ecosystem/mobx-form

Package Overview
Dependencies
Maintainers
0
Versions
92
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mobx-ecosystem/mobx-form - npm Package Compare versions

Comparing version 2.10.26-alpha.3 to 2.10.27

dist/form-service.test.d.ts

4

dist/autocompete-field-service.d.ts

@@ -7,4 +7,4 @@ import { FieldService } from "./field-service";

constructor(initValue?: ValueType<T>);
get validate(): (() => Promise<void>) | undefined;
set validate(validate: (() => Promise<void>) | undefined);
get validate(): (() => Promise<unknown>) | undefined;
set validate(validate: (() => Promise<unknown>) | undefined);
setValue: (value: ValueType<T>, { inputValue, withNotification, withBlur }: {

@@ -11,0 +11,0 @@ inputValue?: string | undefined;

import { FormValues, IField, IFormable } from './types';
export declare class CombinedFormFieldService<T extends IFormable = IFormable> implements IField {
validate?(): Promise<void>;
private _touched;

@@ -25,3 +24,2 @@ private _disabled;

removeByIndex: (index: number) => void;
private _validate;
reset: () => void;

@@ -31,2 +29,3 @@ setAsInit: () => void;

touch: () => void;
validate: () => Promise<void[]>;
}

@@ -1,2 +0,2 @@

import { FormService } from "form-service";
import { FormService } from "./form-service";
import { IForm, ValidationType } from "types";

@@ -3,0 +3,0 @@ export declare class CombinedFormService implements IForm<any> {

@@ -11,3 +11,3 @@ import { IField, ValueType } from './types';

}>;
validate?: () => Promise<void>;
validate?: () => Promise<unknown>;
_serviceType: string;

@@ -14,0 +14,0 @@ private _initValue?;

import { FieldService } from './field-service';
import { FormErrors, FormValues, IForm, ValidationType } from './types';
import { CombinedFormFieldService } from './combined-form-field-service';
import { AutocompleteFieldService } from 'autocompete-field-service';
import { AutocompleteFieldService } from './autocompete-field-service';
export declare class FormService<T extends Record<string, FieldService<any> | CombinedFormFieldService | AutocompleteFieldService<any> | Record<string, unknown>>> implements IForm<T> {

@@ -6,0 +6,0 @@ fields: T;

@@ -1,1 +0,1 @@

import{isEqual as e}from"lodash";import{makeAutoObservable as i,makeObservable as t,observable as r,action as s,computed as l}from"mobx";import a from"mitt";class n{constructor(e,t){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=a()}}),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=t}get initValue(){return this._initValue}set initValue(e){this._initValue=e,this._value=e,this.validate&&this.validate()}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 u(e,i,t,r){return new(t||(t=Promise))((function(s,l){function a(e){try{u(r.next(e))}catch(e){l(e)}}function n(e){try{u(r.throw(e))}catch(e){l(e)}}function u(e){var i;e.done?s(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 o,h;const b=e=>{o=e.validation.validate,h=e.validation.preSubmitValidationError},d=()=>{if(!o||!h)throw new Error("You must define configureForm to configure mobx-form")};class c{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=>{this.value.push(e),this.setTouched(!0),this._validate()}}),Object.defineProperty(this,"removeByIndex",{enumerable:!0,configurable:!0,writable:!0,value:e=>{this.value.splice(e,1),this.setTouched(!0),this._validate()}}),Object.defineProperty(this,"_validate",{enumerable:!0,configurable:!0,writable:!0,value:()=>{var e;this.value.forEach((e=>e.formService.validate())),null===(e=this.validate)||void 0===e||e.call(this)}}),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.setTouched(!0)}}),i(this),this.initValue=e||[]}get initValue(){return this._initValue}set initValue(e){this._initValue=e,this._value=e.slice(0),this.setTouched(!1),this._validate()}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 f{constructor(e){Object.defineProperty(this,"field",{enumerable:!0,configurable:!0,writable:!0,value:new n(null)}),Object.defineProperty(this,"inputField",{enumerable:!0,configurable:!0,writable:!0,value:new n("")}),Object.defineProperty(this,"setValue",{enumerable:!0,configurable:!0,writable:!0,value:(e,{inputValue:i="",withNotification:t=!0,withBlur:r=!0})=>{var s,l,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===(l=(s=this.field).validate)||void 0===l||l.call(s),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 v{constructor(e,i){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:()=>u(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==h||h()}))}),Object.defineProperty(this,"validate",{enumerable:!0,configurable:!0,writable:!0,value:(e="only-touched")=>u(this,void 0,void 0,(function*(){const i=this.getValues(),t=yield null==o?void 0:o(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 n||e instanceof c||e instanceof f)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 n||e[t]instanceof c||e[t]instanceof f)&&(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 n||e instanceof c||e instanceof f?i(e,t):"object"==typeof e&&Object.keys(e||{}).forEach((r=>{this.bypassFields(null==e?void 0:e[r],i,null==t?void 0:t[r])}))}}),Object.defineProperty(this,"setValidationToFields",{enumerable:!0,configurable:!0,writable:!0,value:()=>{this.bypassFields(this.fields,(e=>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()))}}),d(),t(this,{fields:r,validationSchema:r,onSubmit:r,setOnSubmit:s,submit:s,validate:s,setValidationSchema:s,keys:l,isValid:l,isTouched:l,canBeSubmitted:l,disabled:l,getValues:s,setFieldsByThis:s,setInitValues:s,setValues:s,resetErrors:s,setErrors:s,setValuesAsInit:s,reset:s,disable:s,enable:s,touch:s}),this.fields=e,this.validationSchema=i,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{f as AutocompleteFieldService,c as CombinedFormFieldService,n as FieldService,v as FormService,d as _checkConfiguration,b as configureForm,h as preSubmitValidationError,o 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)}}),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)}}),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:()=>Promise.all(this.value.map((e=>e.formService.validate("everything"))))}),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)}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();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);console.log({errors:t,fieldValues:i,type:e}),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)=>{if(e instanceof r||e instanceof o||e instanceof h)return i(e,t);"object"==typeof e&&Object.keys(e||{}).forEach((r=>{this.bypassFields(null==e?void 0:e[r],i,null==t?void 0:t[r])}))}}),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};

@@ -17,3 +17,3 @@ import { FormService } from "./form-service";

isInit: boolean;
validate?: () => Promise<void>;
validate?: () => Promise<unknown>;
reset(): void;

@@ -25,3 +25,3 @@ setAsInit(): void;

fields: T;
validate: (type: ValidationType) => Promise<void>;
validate: (type: ValidationType) => Promise<unknown>;
keys: string[];

@@ -28,0 +28,0 @@ isValid: boolean;

@@ -5,3 +5,3 @@ {

"private": false,
"version": "2.10.26-alpha.3",
"version": "2.10.27",
"description": "provides the ability to use forms with validation in MobX stores",

@@ -26,3 +26,3 @@ "main": "dist/index.js",

"pub": "yarn build && yarn publish --access public",
"test": "echo \"Error: no test specified\" && exit 1"
"test": "jest"
},

@@ -29,0 +29,0 @@ "files": [

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc