Skip to content

fix: update form validation typings #526 #538

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 28, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions types/form/form.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ declare interface FieldDecoratorOptions {
preserve?: boolean;
}

export type ValidateCallback = (errors: Error[], values: any) => void;

export interface WrappedFormUtils {
/**
* Two-way binding for form, single file template can be bound using the directive v-decorator.
Expand Down Expand Up @@ -240,7 +242,7 @@ export interface WrappedFormUtils {
* If you don't specify a parameter, all the fields will be reset.
* @type Function (Function([names: string[]]))
*/
resetFields(names: string[]): void;
resetFields(names?: string[]): void;

/**
* Set value and error state of fields
Expand All @@ -259,24 +261,25 @@ export interface WrappedFormUtils {
* If you don't specify the parameter of fieldNames, you will validate all fields.
* @type Function
*/
validateFields(
fieldNames: string[],
options: ValidateFieldOptions,
callback: (erros: Error[], values: any) => any,
): void;
validateFields(fieldNames: string[], options: ValidateFieldOptions, callback: ValidateCallback): void;
validateFields(fieldNames: string[], callback: ValidateCallback): void;
validateFields(options: ValidateFieldOptions, callback: ValidateCallback): void;
validateFields(callback: ValidateCallback): void;
validateFields(): void;

/**
* This function is similar to validateFields, but after validation, if the target field is not in visible area of form,
* form will be automatically scrolled to the target field area.
* @type Function
*/
validateFieldsAndScroll(
fieldNames: string[],
options: ValidateFieldOptions,
callback: (erros: Error[], values: any) => any,
): void;
validateFieldsAndScroll(fieldNames?: string[], options?: Object, callback?: ValidateCallback): void;
validateFieldsAndScroll(fieldNames?: string[], callback?: ValidateCallback): void;
validateFieldsAndScroll(options?: Object, callback?: ValidateCallback): void;
validateFieldsAndScroll(callback?: ValidateCallback): void;
validateFieldsAndScroll(): void;
}


export interface IformCreateOption {
/**
* Only supports the use of Form.create({})(CustomizedForm). declare props on form(like vue props)
Expand Down