Skip to content

Commit

Permalink
fix(d.ts): remove unused $modelValue; support null for $parser/$forma…
Browse files Browse the repository at this point in the history
…tter
  • Loading branch information
Jiaqi Liu committed Mar 6, 2019
1 parent 775082d commit 1ec6890
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -617,10 +617,12 @@ class MyField extends Component {}
`EasyField` 是对`Field`的二次封装,它提供了基于浏览器原生表单控件实现的表单域快捷调用,同时也提供了统一的 `value` `onChange` `onFocus` `onBlur` 等接口方法来与其它第三方组件库对接。
**特别提醒:`EasyField`会默认对所有的字符串输入做前后空格的过滤。如果不需要这个特性,可以通过重写`$parser`属性来关闭该功能:**
**特别提醒:`EasyField`会默认对所有的字符串输入做前后空格的过滤。如果不需要这个特性,可以通过重写`$parser`属性或者将其设置为`null`来关闭该功能:**
```javascript
<EasyField name="name" type="username" $parser={value => value} />
// OR
<EasyField name="name" type="username" $parser={null} />
```
`EasyField`内置了一些常用的校验方法,例如:
Expand Down
9 changes: 4 additions & 5 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ export type FieldError<Validators> = { [K in keyof Validators]: DetectAny<Valida

export interface FieldState<T = string, Validators = {}> {
$value: T;
$modelValue: T;
$viewValue: any,
$viewValue: any;
$valid: boolean;
$invalid: boolean;
$dirty: boolean;
Expand Down Expand Up @@ -167,8 +166,8 @@ export interface FieldComponentProps<T = string, P = {}, Fields = {}, WeakFields
$onFieldChange?: ((newValue: T, preValue: T, $formutil: $Formutil<Fields, P, WeakFields>) => void);
$validators?: Validators<T, Fields, P, WeakFields>;
$asyncValidators?: never;
$parser?: ($viewValue: any, $setViewValue: ($newViewValue: any) => any) => T;
$formatter?: ($modelValue: T, $setModelValue: ($newModelValue: T) => T) => any;
$parser?: (($viewValue: any, $setViewValue: ($newViewValue: any) => any) => T) | null;
$formatter?: (($modelValue: T, $setModelValue: ($newModelValue: T) => T) => any) | null;
name?: string;
component?: React.ComponentType;
render?: (($fieldutil: $Fieldutil<T, P>) => React.ReactNode);
Expand Down Expand Up @@ -245,7 +244,7 @@ export interface $Fieldutil<T = string, Validators = {}, Fields = {}, WeakFields
$reset(newState?: Partial<FieldState<T, Validators>>): FieldState<T, Validators>;

$render($viewValue: any, callback?: () => void): FieldState<T, Validators>;
$setValue($modelValue: any, callback?: () => void): FieldState<T, Validators>;
$setValue($modelValue: T, callback?: () => void): FieldState<T, Validators>;
$setState(newState: Partial<FieldState<T, Validators>>, callback?: () => void): FieldState<T, Validators>;
$setTouched(touched: boolean, callback?: () => void): FieldState<T, Validators>;
$setDirty(dirty: boolean, callback?: () => void): FieldState<T, Validators>;
Expand Down

0 comments on commit 1ec6890

Please sign in to comment.