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(cdk:forms): useFormGroup support nested objects #1021

Merged
merged 1 commit into from
Jul 15, 2022

Conversation

danranVm
Copy link
Member

@danranVm danranVm commented Jul 15, 2022

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our guidelines
  • Tests for the changes have been added/updated or not needed
  • Docs and demo have been added/updated or not needed

What is the current behavior?

const nameGroup = useFormGroup({
  firstName: ['', required],
  lastName: ['', required],
})

const addressGroup = useFormGroup({
  city: ['', required],
  street: ['', required],
  zip: [''],
})

// 不支持直接嵌套 object
const formGroup = useFormGroup({
  name: nameGroup,
  address: addressGroup,
})

// 需要手动声明 string[]
const formArray = useFormArray<string[]>([['', required]])

What is the new behavior?

// 直接嵌套使用
const formGroup = useFormGroup({
  name: {
    firstName: ['', required],
    lastName: ['', required],
  },
  address: {
    city: ['', required],
    street: ['', required],
    zip: [''],
  },
})

// 只需要声明 string 
const formArray1 = useFormArray<string>([['', required]])
// 或者利用反向推导,直接得到对应类型
const formArray2 = useFormArray([['', required]])

Other information

@idux-bot
Copy link

idux-bot bot commented Jul 15, 2022

This preview will be available after the AzureCI is passed.

@codecov
Copy link

codecov bot commented Jul 15, 2022

Codecov Report

Merging #1021 (e8096ef) into main (33b43bb) will decrease coverage by 0.00%.
The diff coverage is 96.25%.

@@            Coverage Diff             @@
##             main    #1021      +/-   ##
==========================================
- Coverage   93.91%   93.91%   -0.01%     
==========================================
  Files         308      308              
  Lines       29355    29386      +31     
  Branches     2531     2534       +3     
==========================================
+ Hits        27568    27597      +29     
- Misses       1787     1789       +2     
Impacted Files Coverage Δ
packages/components/form/src/FormItem.tsx 97.48% <80.00%> (-1.19%) ⬇️
packages/cdk/forms/src/controls.ts 100.00% <100.00%> (ø)
packages/cdk/forms/src/types.ts 100.00% <100.00%> (ø)
packages/cdk/forms/src/useForms.ts 100.00% <100.00%> (ø)
packages/components/form/src/types.ts 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 33b43bb...e8096ef. Read the comment docs.

@danranVm danranVm merged commit bdb96df into IDuxFE:main Jul 15, 2022
@danranVm danranVm deleted the feat-cdk-forms branch July 15, 2022 07:05
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

Successfully merging this pull request may close these issues.

1 participant