Skip to content

Instantly share code, notes, and snippets.

@kitze
Created January 5, 2017 13:18
Show Gist options
  • Save kitze/a4f04b2b6e52fa5dc4e7167fac13d3dc to your computer and use it in GitHub Desktop.
Save kitze/a4f04b2b6e52fa5dc4e7167fac13d3dc to your computer and use it in GitHub Desktop.
bindField function for mobx-react-form
export const bindField = (form, field, {error = 'error', value = 'value', floatLabel = false, onChangeFn, onChange = 'onChange', placeholder = 'placeholder'}={}) => ({
name: form.$(field).name,
[value]: form.$(field).value,
[placeholder]: form.$(field).label,
...floatLabel === true && {floatingLabelText: form.$(field).label},
[onChange]: onChangeFn || form.$(field).sync,
[error]: form.$(field).error
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment