Created
March 22, 2017 17:07
-
-
Save methodik/afae0abe9a98842a9538f6cae7fa5b0e to your computer and use it in GitHub Desktop.
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
import React from 'react' | |
import Fieldset from './Fieldset' | |
import Field from './Field' | |
// const SPACE_REGEX = / /g; | |
// const NONWORD_REGEX = /[^a-z0-9_-+]/ig; | |
export default class FormStep extends React.Component { | |
constructor (props) { | |
super(props); | |
this.state = {hasErrors: false}; | |
} | |
render () { | |
const step = this.props.step; | |
if (!step) { | |
return (<div className="FormStep"/>); | |
} | |
const name = step.name || ''; | |
const items = step.type === 'multi' ? step.value : [step]; | |
const slots = this.props.children && (Array.isArray(this.props.children) ? | |
this.props.children.slice() : [this.props.children] | |
); | |
const userValues = this.props.userValues; | |
console.log('STEP', {userValues, slots}, this.props); | |
return ( | |
<div className="FormStep" | |
data-has-errors={this.state.hasErrors} | |
data-name={name} | |
> | |
{ | |
items.map(field => { | |
const fieldName = field === step ? name : `${name}_${field.name}`; | |
const currentValue = userValues[field.name]; | |
console.log('FIELD in step', {fieldName, field, currentValue}); | |
return ( | |
{slots && field.type === 'slot' ? slots.shift() : ( | |
<Fieldset key={field.name} type={field.type} name={field.name}> | |
{field.overview ? (<p>{field.overview}</p>) : null} | |
{field.title ? (<span className="FormInputQuestion">{field.title}</span>) : null} | |
<Field {...field} name={fieldName} currentValue={currentValue}/> | |
</Fieldset> | |
)} | |
); | |
}) | |
}, | |
</div> | |
); | |
} | |
} |
premasagar
commented
Mar 22, 2017
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment