Skip to content

Commit

Permalink
fix(core): fix value is overwritten by default (#917)
Browse files Browse the repository at this point in the history
  • Loading branch information
janryWang authored Jun 30, 2020
1 parent fae0f96 commit f3ad159
Show file tree
Hide file tree
Showing 6 changed files with 160 additions and 93 deletions.
51 changes: 51 additions & 0 deletions docs/zh-cn/schema-develop/faq.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
```jsx
import React from 'react'
import ReactDOM from 'react-dom'
import {
SchemaForm,
FormButtonGroup,
SchemaMarkupField as Field,
Submit,
FormPath,
createFormActions
} from '@formily/next'
import { Input, FormCard, setup } from '@formily/next-components'
import '@alifd/next/dist/next.css'

setup()

const actions = createFormActions()

const App = () => {
return (
<SchemaForm
initialValues={{
container: [{ bb: '123' }, { bb: '123' }]
}}
effects={($, { setFieldState }) => {
$('onFieldChange', 'container.*.bb').subscribe(
async ({ value, name }) => {
const siblingName = FormPath.transform(name, /\d+/, $d => {
return `container.${$d}.aa`
})
await setFieldState(siblingName, state => {
state.visible = value !== '123'
})
}
)
}}
>
<Field name="container" type="array">
<Field name="object" type="object">
<FormCard>
<Field name="aa" required type="string" />
<Field name="bb" required type="string" />
</FormCard>
</Field>
</Field>
<button type="submit">Submit</button>
</SchemaForm>
)
}
ReactDOM.render(<App />, document.getElementById('root'))
```
Loading

0 comments on commit f3ad159

Please sign in to comment.