Skip to content

Commit 04acfa7

Browse files
author
foxhound87
committed
fix: ValidationPlugins interface allows custom plugins keys
1 parent 69ce4c4 commit 04acfa7

File tree

11 files changed

+57
-24
lines changed

11 files changed

+57
-24
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ npm-debug.log
1414
coverage.lcov
1515
codecov.yml
1616
yarn-error.log
17+
.qodo

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# 6.11.1 (master)
2+
3+
- `ValidationPlugins` interface allows custom plugins keys.
4+
- Introduced `autocomplete` field prop.
5+
- Deprecated `checkValidationPlugins` method.
6+
17
# 6.11.0 (master)
28

39
- Full `null` values support for fields values.

src/Base.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ export default class Base implements BaseInterface {
303303
$autoFocus: _try(SeparatedPropsMode.autoFocus),
304304
$ref: _try(SeparatedPropsMode.refs),
305305
$nullable: _try(SeparatedPropsMode.nullable),
306+
$autocomplete: _try(SeparatedPropsMode.autocomplete),
306307
};
307308

308309
const field = this.state.form.makeField(

src/Bindings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export default class Bindings implements BindingsInterface {
2121
label: FieldPropsEnum.label,
2222
placeholder: FieldPropsEnum.placeholder,
2323
disabled: FieldPropsEnum.disabled,
24+
autocomplete: FieldPropsEnum.autocomplete,
2425
onChange: FieldPropsEnum.onChange,
2526
onBlur: FieldPropsEnum.onBlur,
2627
onFocus: FieldPropsEnum.onFocus,

src/Field.ts

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ const setupFieldProps = (instance: FieldInterface, props: any, data: any) =>
8181
$interceptors: props.$interceptors || data?.interceptors || null,
8282
$ref: props.$ref || data?.ref || undefined,
8383
$nullable: props.$nullable || data?.nullable || false,
84+
$autocomplete: props.$autocomplete || data?.autocomplete || undefined,
8485
});
8586

8687
const setupDefaultProp = (
@@ -162,6 +163,7 @@ export default class Field extends Base implements FieldInterface {
162163
$inputMode: string = undefined;
163164
$ref: any = undefined;
164165
$nullable: boolean = false;
166+
$autocomplete: string|undefined = undefined;
165167

166168
showError: boolean = false;
167169
errorSync: string | null = null;
@@ -259,7 +261,7 @@ export default class Field extends Base implements FieldInterface {
259261
this.state = state;
260262

261263
this.setupField(key, path, struct, data, props, update);
262-
this.checkValidationPlugins();
264+
// this.checkValidationPlugins();
263265
this.initNestedFields(data, update);
264266

265267
this.incremental = this.hasIncrementalKeys;
@@ -366,6 +368,10 @@ export default class Field extends Base implements FieldInterface {
366368
return propGetter(this, FieldPropsEnum.nullable);
367369
}
368370

371+
get autocomplete(): string|undefined {
372+
return propGetter(this, FieldPropsEnum.autocomplete);
373+
}
374+
369375
get ref() {
370376
return propGetter(this, FieldPropsEnum.ref)
371377
}
@@ -687,26 +693,26 @@ export default class Field extends Base implements FieldInterface {
687693
return toJS(val);
688694
}
689695

690-
checkValidationPlugins(): void {
691-
const { drivers } = this.state.form.validator;
692-
const form = this.state.form.name ? `${this.state.form.name}/` : "";
693-
694-
if (_.isNil(drivers.dvr) && !_.isNil(this.rules)) {
695-
throw new Error(
696-
`The DVR validation rules are defined but no DVR plugin provided. Field: "${
697-
form + this.path
698-
}".`
699-
);
700-
}
701-
702-
if (_.isNil(drivers.vjf) && !_.isNil(this.validators)) {
703-
throw new Error(
704-
`The VJF validators functions are defined but no VJF plugin provided. Field: "${
705-
form + this.path
706-
}".`
707-
);
708-
}
709-
}
696+
// checkValidationPlugins(): void {
697+
// const { drivers } = this.state.form.validator;
698+
// const form = this.state.form.name ? `${this.state.form.name}/` : "";
699+
700+
// if (_.isNil(drivers.dvr) && !_.isNil(this.rules)) {
701+
// throw new Error(
702+
// `The DVR validation rules are defined but no DVR plugin provided. Field: "${
703+
// form + this.path
704+
// }".`
705+
// );
706+
// }
707+
708+
// if (_.isNil(drivers.vjf) && !_.isNil(this.validators)) {
709+
// throw new Error(
710+
// `The VJF validators functions are defined but no VJF plugin provided. Field: "${
711+
// form + this.path
712+
// }".`
713+
// );
714+
// }
715+
// }
710716

711717
initNestedFields(field: any, update: boolean): void {
712718
const fields = _.isNil(field) ? null : field.fields;

src/models/FieldInterface.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export interface FieldInterface extends BaseInterface {
6666
update: boolean
6767
): void;
6868
getComputedProp(key: any): any;
69-
checkValidationPlugins(): void;
69+
// checkValidationPlugins(): void;
7070
initNestedFields(field: any, update: boolean): void;
7171
invalidate(message?: string, deep?: boolean, async?: boolean): void;
7272
setValidationAsyncData(valid: boolean, message: string): void;

src/models/FieldProps.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ export enum FieldPropsEnum {
6262
inputMode = "inputMode",
6363
onKeyDown = "onKeyDown",
6464
onKeyUp = 'onKeyUp',
65-
// construction
6665
class = "class",
6766
nullable = "nullable",
67+
autocomplete = "autocomplete",
6868
}
6969

7070
export type FieldPropsType = {
@@ -112,4 +112,5 @@ export enum SeparatedPropsMode {
112112
refs = 'refs',
113113
classes = 'classes',
114114
nullable = 'nullable',
115+
autocomplete = 'autocomplete',
115116
}

src/models/ValidatorInterface.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export type ValidationPlugin = {
3636
};
3737

3838
export interface ValidationPlugins {
39+
[key: string]: ValidationPlugin | undefined;
3940
vjf?: ValidationPlugin;
4041
dvr?: ValidationPlugin;
4142
svk?: ValidationPlugin;

src/props.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export const props: PropsGroupsInterface = {
3232
FieldPropsEnum.inputMode,
3333
FieldPropsEnum.ref,
3434
FieldPropsEnum.nullable,
35+
FieldPropsEnum.autocomplete,
3536
],
3637
handlers: [
3738
FieldPropsEnum.onChange,
@@ -92,6 +93,8 @@ export const props: PropsGroupsInterface = {
9293
SeparatedPropsMode.inputMode,
9394
SeparatedPropsMode.refs,
9495
SeparatedPropsMode.classes,
96+
SeparatedPropsMode.nullable,
97+
SeparatedPropsMode.autocomplete,
9598
],
9699
functions: [
97100
FieldPropsEnum.computed,

tests/data/forms/flat/form.r.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const fields = {
1212
value: "s.jobs@apple.com",
1313
validators: [isEmail],
1414
related: ["emailConfirm"],
15+
autocomplete: "on",
1516
},
1617
emailConfirm: {
1718
label: "Email",
@@ -43,7 +44,7 @@ class NewForm extends MobxReactForm {
4344

4445
plugins(): ValidationPlugins {
4546
return {
46-
vjf: vjf(),
47+
xyz: vjf(), // custom xyz plugin
4748
};
4849
}
4950

0 commit comments

Comments
 (0)