Skip to content

Instantly share code, notes, and snippets.

@dtothefp
Last active February 20, 2016 18:04
Show Gist options
  • Save dtothefp/d5b3c03b015859252b39 to your computer and use it in GitHub Desktop.
Save dtothefp/d5b3c03b015859252b39 to your computer and use it in GitHub Desktop.
export const formId = 'email_signup_form';
export const data = [
{
name: 'email',
type: 'email',
classes: 'form-input',
label: {
classes: 'form-label',
text: 'Email address'
}
},
{
name: 'zipcode',
type: 'text',
classes: 'form-input',
value: 'some initial value in the input'
label: {
classes: 'form-label',
text: 'ZIP code'
},
validation: {
validateAs: 'zip'
}
},
{
type: 'radio',
name: 'my_radio',
value: 'first'
},
{
type: 'radio',
name: 'my_radio',
value: 'second'
},
{
type: 'radio',
name: 'my_radio',
value: 'third'
}
];
export function get({omitValue = []}) {
return data.map(inputData => {
const {name, value} = inputData;
let omit;
if (_.isBoolean(omitValue) && omitValue) {
omit = omitValue;
} else {
const omitByName = omitValue.indexOf(name) !== -1;
const omitByValue = omitValue.indexOf(value) !== -1;
omit = omitByName || omitByValue;
}
omit ? _.omit(inputData, 'value') : inputData;
})
}
import {get as getFormData} from './form-data.js';
class FormComp extends Component {
constructor(props) {
super(props);
this.inputs = getFormDate({omit: ['zipcode']}).map((inputData, i) => <Input {...inputData} key={`form_comp_${i}`} required />);
}
render() {
return (
<Form>
{this.inputs}
</Form>
)
}
}
import {get as getFormData} from './form-data.js';
const formData = getFormData({omitValue: true});
Actions.FormActions.register('some_form_id', formData);
//or
const formData = getFormData({omitValue: ['email', 'zipcode', 'second', 'third']}); //omit all vals except the first radio button
Actions.FormActions.register('some_form_id', formData);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment