-
Notifications
You must be signed in to change notification settings - Fork 716
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: arrayField allowEmpty=false, condiction show arrayField, add nee…
…d to call twice
- Loading branch information
Showing
4 changed files
with
63 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { ArrayField, TextArea, Form, Button, useFormState } from '@douyinfe/semi-ui'; | ||
import React, { useRef, useState } from 'react'; | ||
|
||
const Demo = () => { | ||
const formRef = useRef(); | ||
const [flag, setFlag] = useState(false); | ||
return ( | ||
<Form ref={formRef} onValueChange={values => console.log(values)} style={{ width: 250 }}> | ||
<Button type="primary" onClick={() => setFlag(!flag)} className="btn-margin-right"> | ||
{!flag ? '开启' : '关闭'} | ||
</Button> | ||
|
||
{flag && ( | ||
<ArrayField field="rules"> | ||
{({ add, arrayFields, addWithInitValue }) => ( | ||
<React.Fragment> | ||
<Button onClick={add} theme="light"> | ||
Add new line | ||
</Button> | ||
<Button | ||
onClick={() => { | ||
addWithInitValue({ name: 'Semi DSM', type: 'Designer' }); | ||
}} | ||
style={{ marginLeft: 8 }} | ||
> | ||
Add new line with init value | ||
</Button> | ||
{arrayFields.map(({ field, key, remove }, i) => ( | ||
<div key={key} style={{ width: 1000, display: 'flex' }}> | ||
<Form.Input | ||
field={`${field}[name]`} | ||
label={`${field}.name`} | ||
style={{ width: 200, marginRight: 16 }} | ||
/> | ||
<Form.Select | ||
field={`${field}[role]`} | ||
label={`${field}.role`} | ||
style={{ width: 120 }} | ||
optionList={[ | ||
{ label: 'Engineer', value: 'Engineer' }, | ||
{ label: 'Designer', value: 'Designer' }, | ||
]} | ||
/> | ||
<Button type="danger" theme="borderless" onClick={remove} style={{ margin: 12 }} /> | ||
</div> | ||
))} | ||
</React.Fragment> | ||
)} | ||
</ArrayField> | ||
)} | ||
</Form> | ||
); | ||
}; | ||
|
||
|
||
export default Demo; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters