gcanti / tcomb-form

Forms library for react
https://gcanti.github.io/tcomb-form
MIT License
1.16k stars 136 forks source link

custom template for checkbox #190

Closed benmonro closed 8 years ago

benmonro commented 9 years ago

currently the checkbox field has the checkbox followed by the label. I'm just curious how you can move customize this? I want to just keep the existing checkbox. I was thinking it'd be something like this:

                fields: {
                    isImaginary: {
                        label: <b>Imaginary Pet?</b>,
                        template: locals => { 
                            return <div>{locals.label} {locals.input}</div>
                        }
                    }
                }
gcanti commented 9 years ago

The minimal template for a checkbox I can think of is:

var Foo = t.struct({
  bar: t.Boolean
});

var options = {
  fields: {
    bar: {
      template: (locals) => {
        return (
          <div>
            <label>{locals.label}</label>
            <input type="checkbox" checked={locals.value} onChange={evt => locals.onChange(evt.target.checked)}/>
          </div>
        );
      }
    }
  }
};