forked from alibaba-fusion/next
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(Field): parseName defaults (alibaba-fusion#683)
* fix(Field): parseName defaults - field constructor saves passed values - field init looks at constructor values for defaults
- Loading branch information
Showing
5 changed files
with
143 additions
and
49 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,74 @@ | ||
# 结构化解析 | ||
|
||
- order: 12 | ||
|
||
使用 parseName 时设置默认值。 | ||
输入名称是 “值” 道具内的路径 | ||
|
||
:::lang=en-us | ||
# Parse Array or Object | ||
|
||
- order: 12 | ||
|
||
Set default values when using parseName. | ||
Input name is path inside `values` prop | ||
|
||
::: | ||
--- | ||
|
||
````jsx | ||
import {Input, Button, Field, Form } from '@alifd/next'; | ||
|
||
|
||
|
||
class Demo extends React.Component { | ||
field = new Field(this, { | ||
parseName: true, | ||
values: { | ||
aaa: ['xxx', 'yyy'], | ||
bbb: { | ||
ccc: 'value c' | ||
} | ||
} | ||
}); | ||
|
||
_handleValidate = () => { | ||
const { | ||
field: { | ||
validate | ||
} | ||
} = this; | ||
|
||
validate(['bbb.ccc']) | ||
}; | ||
|
||
render() { | ||
const { | ||
field, | ||
field: { | ||
init, | ||
} | ||
} = this; | ||
|
||
console.log(this) | ||
|
||
return <Form field={field}> | ||
<Button onClick={this._handleValidate}>validate</Button> | ||
<Form.Item label="aaa" key="aaa"> | ||
<Input name="aaa.0"/> | ||
</Form.Item> | ||
<Form.Item label="ccc" key="ccc"> | ||
<Input name="bbb.ccc"/> | ||
</Form.Item> | ||
</Form>; | ||
} | ||
} | ||
|
||
ReactDOM.render(<Demo/>, mountNode); | ||
```` | ||
|
||
````css | ||
.demo .next-btn { | ||
margin-right: 5px; | ||
} | ||
```` |
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
Oops, something went wrong.