Skip to content

Instantly share code, notes, and snippets.

@methodik
Created March 22, 2017 17:07
Show Gist options
  • Save methodik/afae0abe9a98842a9538f6cae7fa5b0e to your computer and use it in GitHub Desktop.
Save methodik/afae0abe9a98842a9538f6cae7fa5b0e to your computer and use it in GitHub Desktop.
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>
);
}
}
@methodik
Copy link
Author

=> Client modified -- refreshing (x2)
=> Errors prevented startup:

While building for web.browser:
client/forms/Step.js:44:23: Unexpected token, expected , (44:23)

While processing files with ecmascript (for target web.browser):
client/forms/Step.js:44:23: Unexpected token, expected , (44:23)

=> Your application has errors. Waiting for file change.
=> Modified -- restarting.
=> Errors prevented startup:

While building for web.browser:
client/forms/Step.js:44:23: Unexpected token, expected , (44:23)

While processing files with ecmascript (for target web.browser):
client/forms/Step.js:44:23: Unexpected token, expected , (44:23)

=> Your application has errors. Waiting for file change.
=> Modified -- restarting.
=> Errors prevented startup:

While building for web.browser:
client/forms/Step.js:44:23: Unexpected token, expected , (44:23)

While processing files with ecmascript (for target web.browser):
client/forms/Step.js:44:23: Unexpected token, expected , (44:23)

=> Your application has errors. Waiting for file change.
=> Modified -- restarting.
=> Errors prevented startup:

While building for web.browser:
client/forms/Step.js:44:23: Unexpected token, expected , (44:23)

While processing files with ecmascript (for target web.browser):
client/forms/Step.js:44:23: Unexpected token, expected , (44:23)

=> Your application has errors. Waiting for file change.

@premasagar
Copy link

premasagar commented Mar 22, 2017

if (field.type === 'slot') {
  return slots && slots.shift() || null;
}

return (
  <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>
);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment