Skip to content

Commit

Permalink
fix: composer error method
Browse files Browse the repository at this point in the history
composer error method
  • Loading branch information
Cla authored and Cla committed Aug 1, 2023
1 parent dd4a84e commit 9118bf4
Show file tree
Hide file tree
Showing 71 changed files with 180 additions and 161 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 6.3.6 (master)
- Fix: composer `error()` method.
- Fix: default models/interfaces have now named exports.
- Fix: check event w/ `isEvent()` to call `preventDefault()` for native support.

# 6.3.5 (master)
- Fix: `parseCheckArray` checks for `incremental` field status.
- Updated `semantic-release`
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ import MobxReactForm from 'mobx-react-form';
const myForm = new MobxReactForm({ fields }, { plugins, hooks });
```

> Learn about more on the docs about the [Form Instance](https://foxhound87.github.io/mobx-react-form/docs/form/)
> Learn more on the docs about the [Form Instance](https://foxhound87.github.io/mobx-react-form/docs/form/)
#### Pass the myForm to a react component

Expand Down Expand Up @@ -150,7 +150,7 @@ export default observer(({ myForm }) => (
));
```

> See more on the docs about the [Event Handlers](https://foxhound87.github.io/mobx-react-form/docs/events/event-handlers.html) and the [Event Hooks](https://foxhound87.github.io/mobx-react-form/docs/events/event-hooks.html).
> See more on the docs about the [Field Props Bindings](https://foxhound87.github.io/mobx-react-form/docs/bindings)
###### Extending the Form class

Expand Down
21 changes: 7 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 11 additions & 11 deletions src/Base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import {
ObservableMap,
} from "mobx";
import _ from "lodash";
import BaseInterface from "./models/BaseInterface";
import StateInterface from "./models/StateInterface";
import FieldInterface from "./models/FieldInterface";
import {BaseInterface} from "./models/BaseInterface";
import {StateInterface} from "./models/StateInterface";
import {FieldInterface} from "./models/FieldInterface";

import {
props,
Expand All @@ -22,7 +22,7 @@ import {
getObservableMapValues,
maxKey,
$try,
$isEvent,
isEvent,
hasIntKeys,
pathToStruct,
} from "./utils";
Expand Down Expand Up @@ -181,7 +181,7 @@ export default class Base implements BaseInterface {
*/
onClear = (...args: any): any =>
this.execHandler(FieldPropsEnum.onClear, args, (e: Event) => {
e.preventDefault();
isEvent(e) && e.preventDefault();
(this as any).clear(true, false);
});

Expand All @@ -190,7 +190,7 @@ export default class Base implements BaseInterface {
*/
onReset = (...args: any): any =>
this.execHandler(FieldPropsEnum.onReset, args, (e: Event) => {
e.preventDefault();
isEvent(e) && e.preventDefault();
(this as any).reset(true, false);
});

Expand All @@ -199,7 +199,7 @@ export default class Base implements BaseInterface {
*/
onSubmit = (...args: any): any =>
this.execHandler(FieldPropsEnum.onSubmit, args, (e: Event, o = {}) => {
e.preventDefault();
isEvent(e) && e.preventDefault();
this.submit(o, { execOnSubmitHook: false });
});

Expand All @@ -208,17 +208,17 @@ export default class Base implements BaseInterface {
*/
onAdd = (...args: any): any =>
this.execHandler(FieldPropsEnum.onAdd, args, (e: Event, val: any) => {
e.preventDefault();
this.add($isEvent(val) ? null : val, false);
isEvent(e) && e.preventDefault();
this.add(isEvent(val) ? null : val, false);
});

/**
Event Handler: On Del
*/
onDel = (...args: any): any =>
this.execHandler(FieldPropsEnum.onDel, args, (e: Event, path: string) => {
e.preventDefault();
this.del($isEvent(path) ? this.path : path, false);
isEvent(e) && e.preventDefault();
this.del(isEvent(path) ? this.path : path, false);
});

/******************************************************************
Expand Down
2 changes: 1 addition & 1 deletion src/Bindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import _ from "lodash";
import { $try } from "./utils";

import { FieldPropsEnum, FieldPropsType } from "./models/FieldProps";
import BindingsInterface from "./models/BindingsInterface";
import { BindingsInterface } from "./models/BindingsInterface";

export default class Bindings implements BindingsInterface {
templates = {
Expand Down
14 changes: 7 additions & 7 deletions src/Field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ import {
import _ from "lodash";
import Base from "./Base";

import { $try, $hasFiles, $isBool, $isEvent, pathToStruct, isArrayFromStruct } from "./utils";
import { $try, hasFiles, isBool, isEvent, pathToStruct, isArrayFromStruct } from "./utils";

import {
parseInput,
parseCheckOutput,
defaultValue,
} from "./parser";

import OptionsModel, { OptionsEnum } from "./models/OptionsModel";
import FieldInterface, { FieldConstructor } from "./models/FieldInterface";
import { OptionsModel, OptionsEnum } from "./models/OptionsModel";
import { FieldInterface, FieldConstructor } from "./models/FieldInterface";
import { FieldPropsEnum } from "./models/FieldProps";

const applyFieldPropFunc = (instance: FieldInterface, prop: any): any => {
Expand Down Expand Up @@ -336,7 +336,7 @@ export default class Field extends Base implements FieldInterface {
: this.getComputedProp(FieldPropsEnum.value);
}

get initial() {
get initial(): any {
return this.$initial
? toJS(this.$initial)
: this.getComputedProp(FieldPropsEnum.initial);
Expand Down Expand Up @@ -416,7 +416,7 @@ export default class Field extends Base implements FieldInterface {
return parseCheckOutput(this, this.validatedWith);
}

get error() {
get error(): string {
if (this.showError === false) return null;
return this.errorAsync || this.errorSync || null;
}
Expand Down Expand Up @@ -472,7 +472,7 @@ export default class Field extends Base implements FieldInterface {

sync = action((e: any, v: any = null) => {
const $get = ($: any) =>
$isBool($, this.value) ? $.target.checked : $.target.value;
isBool($, this.value) ? $.target.checked : $.target.value;

// assume "v" or "e" are the values
if (_.isNil(e) || _.isNil(e.target)) {
Expand Down Expand Up @@ -539,7 +539,7 @@ export default class Field extends Base implements FieldInterface {
const e = args[0];
let files: unknown[] | null = null;

if ($isEvent(e) && $hasFiles(e)) {
if (isEvent(e) && hasFiles(e)) {
files = _.map(e.target.files);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import Validator from "./Validator";
import State from "./State";
import Field from "./Field";
import ValidatorInterface from "./models/ValidatorInterface";
import FieldInterface, { FieldConstructor } from "./models/FieldInterface";
import FormInterface, { FieldsDefinitions, FormConfig } from "./models/FormInterface";
import { FieldInterface, FieldConstructor } from "./models/FieldInterface";
import { FormInterface, FieldsDefinitions, FormConfig } from "./models/FormInterface";
import { FieldPropsEnum } from "./models/FieldProps";
import { OptionsEnum } from "./models/OptionsModel";

Expand Down
4 changes: 2 additions & 2 deletions src/Options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import _ from "lodash";

import { uniqueId } from "./utils";

import OptionsModel from "./models/OptionsModel";
import OptionsInterface from "./models/OptionsInterface";
import {OptionsModel} from "./models/OptionsModel";
import {OptionsInterface} from "./models/OptionsInterface";

export default class Options implements OptionsInterface {
options: OptionsModel = {
Expand Down
10 changes: 5 additions & 5 deletions src/State.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ import {
$try,
} from "./utils";

import StateInterface from "./models/StateInterface";
import { RuntimeMode } from "./models/StateInterface";
import OptionsInterface from "./models/OptionsInterface";
import BindingsInterface from "./models/BindingsInterface";
import FormInterface from "./models/FormInterface";
import { StateInterface } from "./models/StateInterface";
import { OptionsInterface } from "./models/OptionsInterface";
import { BindingsInterface } from "./models/BindingsInterface";
import { FormInterface } from "./models/FormInterface";
import { OptionsEnum } from "./models/OptionsModel";
import FieldInterface from "./models/FieldInterface";
import { FieldInterface } from "./models/FieldInterface";

export default class State implements StateInterface {
mode = RuntimeMode.mixed;
Expand Down
4 changes: 2 additions & 2 deletions src/Validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import ValidatorInterface, {
ValidationPluginInterface,
ValidationPlugins,
} from "./models/ValidatorInterface";
import FormInterface from "./models/FormInterface";
import FieldInterface from "./models/FieldInterface";
import { FormInterface } from "./models/FormInterface";
import { FieldInterface } from "./models/FieldInterface";
import { OptionsEnum } from "./models/OptionsModel";

export default class Validator implements ValidatorInterface {
Expand Down
4 changes: 2 additions & 2 deletions src/composer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FieldPropsEnum } from "./models/FieldProps";
import FormInterface from "./models/FormInterface";
import { FormInterface } from "./models/FormInterface";

export const composer = (forms: { [key in string]: FormInterface }) => {

Expand All @@ -25,7 +25,7 @@ export const composer = (forms: { [key in string]: FormInterface }) => {
.every(((val: boolean) => val === true));

const error = () => Object.values(check(FieldPropsEnum.hasError))
.every(((val: boolean) => val === true));
.some(((val: boolean) => val === true));

const clear = ({ deep = true, execHook = false }
: { deep?: boolean, execHook?: boolean } = {
Expand Down
16 changes: 9 additions & 7 deletions src/models/BaseInterface.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { ObservableMap } from "mobx";
import SharedActionsInterface from "./SharedActionsInterface";
import SharedEventsInterface from "./SharedEventsInterface";
import SharedHelpersInterface from "./SharedHelpersInterface";
import SharedInitializerInterface from "./SharedInitializerInterface";
import SharedUtilsInferface from "./SharedUtilsInterface";
import StateInterface from "./StateInterface";
export default interface BaseInterface
import {SharedActionsInterface} from "./SharedActionsInterface";
import {SharedEventsInterface} from "./SharedEventsInterface";
import {SharedHelpersInterface} from "./SharedHelpersInterface";
import {SharedInitializerInterface} from "./SharedInitializerInterface";
import {SharedUtilsInferface} from "./SharedUtilsInterface";
import {StateInterface} from "./StateInterface";
export interface BaseInterface
extends SharedInitializerInterface,
SharedActionsInterface,
SharedEventsInterface,
Expand Down Expand Up @@ -40,3 +40,5 @@ export default interface BaseInterface
onAdd(args: any): any;
onDel(args: any): any;
}

export default BaseInterface;
8 changes: 4 additions & 4 deletions src/models/BindingsInterface.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import Bindings from "../Bindings";
import { FieldPropsEnum } from "./FieldProps";
import { FieldPropsEnum, FieldPropsType } from "./FieldProps";

import { FieldPropsType } from "./FieldProps";

export default interface BindingsInterface {
export interface BindingsInterface {
templates: {
[index: string]: {
[key: string]: ({ field, props, keys }: any) => any;
Expand All @@ -23,3 +21,5 @@ export default interface BindingsInterface {

register: (bindings: FieldPropsType) => Bindings;
}

export default BindingsInterface;
11 changes: 7 additions & 4 deletions src/models/FieldInterface.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import BaseInterface from "./BaseInterface";
import OptionsModel from "./OptionsModel";
import StateInterface from "./StateInterface";
export default interface FieldInterface extends BaseInterface {
import {BaseInterface} from "./BaseInterface";
import {OptionsModel} from "./OptionsModel";
import {StateInterface} from "./StateInterface";
export interface FieldInterface extends BaseInterface {
incremental: boolean;
hasInitialNestedFields: boolean;
id: string | undefined;
key: string | undefined;
Expand Down Expand Up @@ -91,3 +92,5 @@ export interface FieldConstructor {
update?: boolean;
state: StateInterface;
}

export default FieldInterface;
12 changes: 7 additions & 5 deletions src/models/FormInterface.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import BaseInterface from "./BaseInterface";
import FieldInterface, { FieldConstructor } from "./FieldInterface";
import OptionsModel from "./OptionsModel";
import ValidatorInterface, { ValidationPlugins } from "./ValidatorInterface";
export default interface FormInterface extends BaseInterface {
import { BaseInterface } from "./BaseInterface";
import { FieldInterface, FieldConstructor } from "./FieldInterface";
import { OptionsModel } from "./OptionsModel";
import { ValidatorInterface, ValidationPlugins } from "./ValidatorInterface";
export interface FormInterface extends BaseInterface {
name: string;
validator: ValidatorInterface;
debouncedValidation: any;
Expand Down Expand Up @@ -68,3 +68,5 @@ export interface FormConfig {
hooks?: any;
handlers?: any;
}

export default FormInterface;
6 changes: 4 additions & 2 deletions src/models/OptionsInterface.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import OptionsModel from "./OptionsModel";
import {OptionsModel} from "./OptionsModel";

export default interface OptionsInterface {
export interface OptionsInterface {
options: OptionsModel;
get: (key?: string, instance?: any) => any;
set: (options: OptionsModel) => void;
}

export default OptionsInterface;
Loading

0 comments on commit 9118bf4

Please sign in to comment.