Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
ant-design-pro
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
duanledexianxianxian
ant-design-pro
Commits
5bcf895a
Commit
5bcf895a
authored
Sep 12, 2018
by
afc163
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor render or AdvancedForm
parent
77d714f2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
66 additions
and
54 deletions
+66
-54
src/pages/Forms/AdvancedForm.js
src/pages/Forms/AdvancedForm.js
+66
-54
No files found.
src/pages/Forms/AdvancedForm.js
View file @
5bcf895a
...
...
@@ -74,6 +74,49 @@ class AdvancedForm extends PureComponent {
window
.
removeEventListener
(
'
resize
'
,
this
.
resizeFooterToolbar
);
}
getErrorInfo
=
()
=>
{
const
{
form
:
{
getFieldsError
},
}
=
this
.
props
;
const
errors
=
getFieldsError
();
const
errorCount
=
Object
.
keys
(
errors
).
filter
(
key
=>
errors
[
key
]).
length
;
if
(
!
errors
||
errorCount
===
0
)
{
return
null
;
}
const
scrollToField
=
fieldKey
=>
{
const
labelNode
=
document
.
querySelector
(
`label[for="
${
fieldKey
}
"]`
);
if
(
labelNode
)
{
labelNode
.
scrollIntoView
(
true
);
}
};
const
errorList
=
Object
.
keys
(
errors
).
map
(
key
=>
{
if
(
!
errors
[
key
])
{
return
null
;
}
return
(
<
li
key
=
{
key
}
className
=
{
styles
.
errorListItem
}
onClick
=
{()
=>
scrollToField
(
key
)}
>
<
Icon
type
=
"
cross-circle-o
"
className
=
{
styles
.
errorIcon
}
/
>
<
div
className
=
{
styles
.
errorMessage
}
>
{
errors
[
key
][
0
]}
<
/div
>
<
div
className
=
{
styles
.
errorField
}
>
{
fieldLabels
[
key
]}
<
/div
>
<
/li
>
);
});
return
(
<
span
className
=
{
styles
.
errorIcon
}
>
<
Popover
title
=
"
葨εζ ‘ιͺδΏ‘ζ―
"
content
=
{
errorList
}
overlayClassName
=
{
styles
.
errorPopover
}
trigger
=
"
click
"
getPopupContainer
=
{
trigger
=>
trigger
.
parentNode
}
>
<
Icon
type
=
"
exclamation-circle
"
/>
<
/Popover
>
{
errorCount
}
<
/span
>
);
};
resizeFooterToolbar
=
()
=>
{
requestAnimationFrame
(()
=>
{
const
sider
=
document
.
querySelectorAll
(
'
.ant-layout-sider
'
)[
0
];
...
...
@@ -87,60 +130,29 @@ class AdvancedForm extends PureComponent {
});
};
render
()
{
const
{
form
,
dispatch
,
submitting
}
=
this
.
props
;
const
{
getFieldDecorator
,
validateFieldsAndScroll
,
getFieldsError
}
=
form
;
const
validate
=
()
=>
{
validateFieldsAndScroll
((
error
,
values
)
=>
{
if
(
!
error
)
{
// submit the values
dispatch
({
type
:
'
form/submitAdvancedForm
'
,
payload
:
values
,
});
}
});
};
const
errors
=
getFieldsError
();
const
getErrorInfo
=
()
=>
{
const
errorCount
=
Object
.
keys
(
errors
).
filter
(
key
=>
errors
[
key
]).
length
;
if
(
!
errors
||
errorCount
===
0
)
{
return
null
;
validate
=
()
=>
{
const
{
form
:
{
validateFieldsAndScroll
},
dispatch
,
}
=
this
.
props
;
validateFieldsAndScroll
((
error
,
values
)
=>
{
if
(
!
error
)
{
// submit the values
dispatch
({
type
:
'
form/submitAdvancedForm
'
,
payload
:
values
,
});
}
const
scrollToField
=
fieldKey
=>
{
const
labelNode
=
document
.
querySelector
(
`label[for="
${
fieldKey
}
"]`
);
if
(
labelNode
)
{
labelNode
.
scrollIntoView
(
true
);
}
};
const
errorList
=
Object
.
keys
(
errors
).
map
(
key
=>
{
if
(
!
errors
[
key
])
{
return
null
;
}
return
(
<
li
key
=
{
key
}
className
=
{
styles
.
errorListItem
}
onClick
=
{()
=>
scrollToField
(
key
)}
>
<
Icon
type
=
"
cross-circle-o
"
className
=
{
styles
.
errorIcon
}
/
>
<
div
className
=
{
styles
.
errorMessage
}
>
{
errors
[
key
][
0
]}
<
/div
>
<
div
className
=
{
styles
.
errorField
}
>
{
fieldLabels
[
key
]}
<
/div
>
<
/li
>
);
});
return
(
<
span
className
=
{
styles
.
errorIcon
}
>
<
Popover
title
=
"
葨εζ ‘ιͺδΏ‘ζ―
"
content
=
{
errorList
}
overlayClassName
=
{
styles
.
errorPopover
}
trigger
=
"
click
"
getPopupContainer
=
{
trigger
=>
trigger
.
parentNode
}
>
<
Icon
type
=
"
exclamation-circle
"
/>
<
/Popover
>
{
errorCount
}
<
/span
>
);
};
});
};
render
()
{
const
{
form
:
{
getFieldDecorator
},
submitting
,
}
=
this
.
props
;
const
{
width
}
=
this
.
state
;
return
(
<
PageHeaderWrapper
title
=
"
ι«ηΊ§θ‘¨ε
"
...
...
@@ -298,8 +310,8 @@ class AdvancedForm extends PureComponent {
})(
<
TableForm
/>
)}
<
/Card
>
<
FooterToolbar
style
=
{{
width
}}
>
{
getErrorInfo
()}
<
Button
type
=
"
primary
"
onClick
=
{
validate
}
loading
=
{
submitting
}
>
{
this
.
getErrorInfo
()}
<
Button
type
=
"
primary
"
onClick
=
{
this
.
validate
}
loading
=
{
submitting
}
>
ζδΊ€
<
/Button
>
<
/FooterToolbar
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment