Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
tujoworker committed Feb 5, 2025
1 parent ce78a0e commit ff992d3
Showing 1 changed file with 105 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useCallback, useEffect } from 'react'
import { Field, Form } from '../../..'
import { Field, Form, Tools } from '../../..'
import { Button, GlobalStatus } from '../../../../../components'
import { debounceAsync } from '../../../../../shared/helpers'

Expand Down Expand Up @@ -386,3 +386,107 @@ function UseValidationComponent() {

return null
}

export function UseData() {
return (
<Form.Handler
id="aid"
data={{
beneficialOwners: {
hasOtherBeneficialOwners: true,
otherBeneficialOwners: [],
hasOtherBeneficialOwners2: true,
otherBeneficialOwners2: [],
},
}}
// onSubmit={console.log}
>
<Form.Card>
<UsingUpdate />
<UsingRemove />

<Tools.Log />
</Form.Card>

<Form.SubmitButton />
</Form.Handler>
)
}

function UsingUpdate() {
// const { update, data } = Form.useData()
const { update, data } = Form.useData<{
beneficialOwners: {
hasOtherBeneficialOwners2: boolean
}
}>('aid')

console.log(
'update data value:',
data.beneficialOwners.hasOtherBeneficialOwners2
)
return (
<Form.Card>
<Field.Boolean
variant="buttons"
path="/beneficialOwners/hasOtherBeneficialOwners2"
onChange={(val) => {
console.log('update onChange value:', val)
if (!val) {
// setTimeout(() => {
update('/beneficialOwners/otherBeneficialOwners2', [])
// }, 1)
}
}}
label="Er det flere?"
/>

<Form.Visibility
animate
pathTrue="/beneficialOwners/hasOtherBeneficialOwners2"
>
<Field.ArraySelection path="/beneficialOwners/otherBeneficialOwners2">
<Field.Option label="Name" value="name" />
</Field.ArraySelection>
</Form.Visibility>
</Form.Card>
)
}

function UsingRemove() {
// const { remove, data } = Form.useData()
const { remove, data } = Form.useData<{
beneficialOwners: {
hasOtherBeneficialOwners: boolean
}
}>('aid')

console.log(
'remove data value:',
data.beneficialOwners.hasOtherBeneficialOwners
)

return (
<Form.Card>
<Field.Boolean
variant="buttons"
path="/beneficialOwners/hasOtherBeneficialOwners"
onChange={(val) => {
console.log('remove onChange value:', val)
if (!val) {
remove('/beneficialOwners/otherBeneficialOwners')
}
}}
label="Er det flere?"
/>
<Form.Visibility
animate
pathTrue="/beneficialOwners/hasOtherBeneficialOwners"
>
<Field.ArraySelection path="/beneficialOwners/otherBeneficialOwners">
<Field.Option label="Name" value="name" />
</Field.ArraySelection>
</Form.Visibility>
</Form.Card>
)
}

0 comments on commit ff992d3

Please sign in to comment.