1
0
mirror of https://github.com/oceanprotocol/commons.git synced 2023-03-15 18:03:00 +01:00

use hidden input to collect files array

This commit is contained in:
Matthias Kretschmann 2019-02-13 12:30:05 +01:00
parent f8405c8e5a
commit 7d3e123bf1
Signed by: m
GPG Key ID: 606EEEF3C479A91F
2 changed files with 18 additions and 5 deletions

View File

@ -9,7 +9,9 @@ import styles from './index.module.scss'
interface FilesProps { interface FilesProps {
files: string[] files: string[]
placeholder: string placeholder: string
help: string help?: string
name: string
onChange: any
// resetForm: any // resetForm: any
} }
@ -40,11 +42,20 @@ export default class Files extends PureComponent<FilesProps, FilesStates> {
public render() { public render() {
const { isFormShown } = this.state const { isFormShown } = this.state
const { files, help, placeholder } = this.props const { files, help, placeholder, name, onChange } = this.props
return ( return (
<> <>
<Help>{help}</Help> {help && <Help>{help}</Help>}
{/* Use hidden input to collect files */}
<input
type="hidden"
name={name}
value={files}
onChange={onChange}
/>
<div className={styles.newItems}> <div className={styles.newItems}>
{files.length > 0 && ( {files.length > 0 && (
<TransitionGroup <TransitionGroup

View File

@ -67,8 +67,10 @@ class Publish extends Component<{}, PublishState> {
</Label> </Label>
<Files <Files
placeholder={value.placeholder} placeholder={value.placeholder}
name={value.name}
help={value.help} help={value.help}
files={this.state.files} files={this.state.files}
onChange={onChange}
/> />
</Row> </Row>
) )
@ -95,7 +97,7 @@ class Publish extends Component<{}, PublishState> {
event: ChangeEvent<HTMLInputElement> | ChangeEvent<HTMLSelectElement> event: ChangeEvent<HTMLInputElement> | ChangeEvent<HTMLSelectElement>
) => { ) => {
this.setState({ this.setState({
[event.target.name]: event.target.value [event.currentTarget.name]: event.currentTarget.value
}) })
} }
@ -103,7 +105,7 @@ class Publish extends Component<{}, PublishState> {
event: ChangeEvent<HTMLInputElement> | ChangeEvent<HTMLSelectElement> event: ChangeEvent<HTMLInputElement> | ChangeEvent<HTMLSelectElement>
) => { ) => {
this.setState({ this.setState({
[event.target.name]: [event.target.value] [event.currentTarget.name]: [event.currentTarget.value]
}) })
} }