Skip to content
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

feat: getFieldProps 返回值增加 name #7

Closed
benjycui opened this issue Jan 13, 2016 · 7 comments
Closed

feat: getFieldProps 返回值增加 name #7

benjycui opened this issue Jan 13, 2016 · 7 comments
Assignees

Comments

@benjycui
Copy link
Member

rc-form 应该不会集成到 antd 里面了,毕竟是纯功能的,而且集成进去可能会导致 antd.Form 变复杂。

但是觉得可以利用 rc-form 简化 FormItem 的用法,如果 getFieldProps 的返回值增加 name 字段,那么 FormItemvalidateStatushelp 都可以自行计算出来,就不需要用户传入了。当然,如果用户传入,就会优先使用用户设置的值。

        <FormItem
          label="用户名:"
          id="name"
          labelCol={{span: 7}}
          wrapperCol={{span: 12}}
          validateStatus={this.getValidateStatus('name')}  // 可自动生成
          hasFeedback
          help={(getFieldError('name') || []).join(', ')}  // 可自动生成
          required>
          <Input {...getFieldProps('name', {
            rules: [
              {require: true, min: 5, message: '用户名至少为 5 个字符'},
              {validator: this.userExists},
            ],
          })} id="name" placeholder="实时校验,输入 JasonWood 看看" />
        </FormItem>

当然,如果连 required 都暴露出来的话,FormItem[required] 也可以自动设置,不过这个需要计算,而 name 值则是直接使用 getFieldProps 的第一个参数就行。

@yiminghe

@benjycui benjycui self-assigned this Jan 13, 2016
@yiminghe
Copy link
Member

增加属性 nameProp 默认 false

getFieldProps('xx',{nameProp:'name'}) =>{name: 'xx'}

@benjycui
Copy link
Member Author

默认 nameProp: 'name' 可好?因为增加这个返回值就是为了简化 FormItem 的 API,不希望因为这样就让 getFieldProps 变得复杂。

另外为什么就不能默认就返回 name? 这应该不会有什么影响,虽然使用的场景不多。

@yiminghe
Copy link
Member

污染组件 prop

@benjycui
Copy link
Member Author

默认 nameProp: 'name' 可好?因为增加这个返回值就是为了简化 FormItem 的 API,不希望因为这样就让 getFieldProps 变得复杂。

这样也不行是吧。。

@yiminghe
Copy link
Member

不能默认返回组件可能不需要的信息

@benjycui
Copy link
Member Author

嗯,我再想一下有没有别的封装办法。。。

@yiminghe
Copy link
Member

getFieldProps 等封装到 formItem

<FormItem form={this.props.form} name="xx" rules={}>
</Form>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants