mirror of
https://gitee.com/ByteDance/flowgram.ai.git
synced 2025-07-07 17:43:29 +08:00
feat: add validate to Form facade, deprecate FieldArray.delete but use remove instead (#94)
* feat: expose validate api in form facade * refactor: deprecate FieldArray.delete but expose remove instead * refactor: only change api on facade
This commit is contained in:
parent
62e53350f1
commit
c75f92d379
@ -85,7 +85,7 @@ export class FieldArrayModel<TValue = FieldValue> extends FieldModel<Array<TValu
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除数组项,该操作会删除数组项的值并销毁数组项的Field模型
|
||||
* Delete the element in given index and delete the corresponding FieldModel as well
|
||||
* @param index
|
||||
*/
|
||||
delete(index: number) {
|
||||
|
||||
@ -19,7 +19,12 @@ export function toFieldArray<TValue>(model: FieldArrayModel<TValue>): FieldArray
|
||||
map: <T = any>(cb: (f: Field, index: number) => T) =>
|
||||
model.map<T>((f, index) => cb(toField(f), index)),
|
||||
append: (value) => toField<TValue>(model.append(value)),
|
||||
/**
|
||||
* @deprecated: use remove instead
|
||||
* @param index
|
||||
*/
|
||||
delete: (index: number) => model.delete(index),
|
||||
remove: (index: number) => model.delete(index),
|
||||
swap: (from: number, to: number) => model.swap(from, to),
|
||||
move: (from: number, to: number) => model.move(from, to),
|
||||
} as FieldArray<TValue>;
|
||||
|
||||
@ -14,6 +14,7 @@ export function toForm<TValue>(model: FormModel): Form<TValue> {
|
||||
state: toFormState(model.state),
|
||||
getValueIn: <TValue = FieldValue>(name: FieldName) => model.getValueIn(name),
|
||||
setValueIn: <TValue>(name: FieldName, value: TValue) => model.setValueIn(name, value),
|
||||
validate: model.validate.bind(model),
|
||||
};
|
||||
|
||||
Object.defineProperty(res, '_formModel', {
|
||||
|
||||
@ -79,10 +79,16 @@ export interface FieldArray<TFieldValue extends FieldValue = FieldValue>
|
||||
*/
|
||||
append: (value: TFieldValue) => Field<TFieldValue>;
|
||||
/**
|
||||
* @deprecated use remove instead
|
||||
* Delete the value and the related field at certain index of the array.
|
||||
* @param index the index of the element to delete
|
||||
*/
|
||||
delete: (index: number) => void;
|
||||
/**
|
||||
* Delete the value and the related field at certain index of the array.
|
||||
* @param index the index of the element to delete
|
||||
*/
|
||||
remove: (index: number) => void;
|
||||
/**
|
||||
* Move an array element from one position to another.
|
||||
* @param from from position
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { FormModel } from '../core/form-model';
|
||||
import { Errors, Validate, ValidateTrigger, Warnings } from './validate';
|
||||
import { Errors, FormValidateReturn, Validate, ValidateTrigger, Warnings } from './validate';
|
||||
import { Field, FieldArray, FieldName, FieldValue } from './field';
|
||||
import { Context } from './common';
|
||||
|
||||
@ -81,6 +81,11 @@ export interface Form<TValues = any> {
|
||||
* @param name path
|
||||
*/
|
||||
setValueIn<TValue>(name: FieldName, value: TValue): void;
|
||||
|
||||
/**
|
||||
* Trigger validate for the whole form.
|
||||
*/
|
||||
validate: () => Promise<FormValidateReturn>;
|
||||
}
|
||||
|
||||
export interface FormRenderProps<TValues> {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user