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

[FR]: Taro组件库,Form组件希望支持下Form.List和Form.useWatch(),使用场景还是比较多的 #2216

Open
chenyong0923 opened this issue Apr 30, 2024 · 2 comments
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers welcome PR 欢迎社区参与 PR

Comments

@chenyong0923
Copy link

这个功能解决了什么问题?

1、表单里有相同的多个控件为最小单元,支持增删改
2、表单field受控,互相依赖,需要监听表单值

你期望的组件设计是怎样的?

interface ListField {
name: string; // 这个返回的是 Form.List 的 name 加索引,如 group_0
key: number;
isListField: boolean; // 这个必须要传给 Form.Item
}

interface ListOperations {
add: (defaultValue?: Value, index?: number) => void;
remove: (index: number) => void;
move: (from: number, to: number) => void;
}

    <Form.List name="enterWorkApplyJobDTOList">
        {(fields, { add, remove }) => {
          return (
            <View>
              {fields.map((field, index) => {
                const _index = index + 1;
                return (
                  <View className={styles.field} key={_index.toString()}>
                    <ReduceFilled
                      className={classnames([styles.field__delete], {
                        [styles.field__delete__disabled]: fields.length < 2,
                      })}
                      onClick={() => {
                        fields.length > 1 && remove(index);
                      }}
                    />

                    <FormItem
                      {...field}
                      name={[field.name, 'jobId']}
                      label=" "
                      labelWidth={0}
                      className={styles.job}
                      rules={[{ required: true, message: '请选择' }]}
                    >
                      <FormPicker
                        mode="selector"
                        icon="DownOutlined"
                        range={
                          jobData?.map((item) => ({
                            label: item.name,
                            value: item.id,
                          })) ?? []
                        }
                        rangeKey="label"
                        placeholder="选择岗位"
                      />
                    </FormItem>
                    <FormItem
                      {...field}
                      name={[field.name, 'amount']}
                      label=" "
                      labelWidth={0}
                      className={styles.count}
                      rules={[{ required: true, message: '请输入' }]}
                    >
                      <Input
                        placeholder="请输入"
                        type="number"
                        suffix=""
                        allowClear={false}
                      />
                    </FormItem>
                  </View>
                );
              })}

              <View
                className={styles.btn}
                onClick={() => {
                  add({ jobId: undefined, amount: undefined });
                }}
              >
                <NewFilled className={styles['btn-icon']} />
                添加岗位
              </View>
            </View>
          );
        }}
      </Form.List>
@xiaoyatong xiaoyatong added enhancement New feature or request good first issue Good for newcomers welcome PR 欢迎社区参与 PR labels May 5, 2024
@oasis-cloud oasis-cloud self-assigned this Jul 3, 2024
@henryzp
Copy link

henryzp commented Nov 12, 2024

这个需求实现的怎么样了?有下文了么?

@henryzp
Copy link

henryzp commented Nov 12, 2024

@oasis-cloud @chenyong0923

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers welcome PR 欢迎社区参与 PR
Projects
None yet
Development

No branches or pull requests

4 participants