UNPKG

@darwino/darwino-react-bootstrap

Version:

A set of Javascript classes and utilities

55 lines (50 loc) 1.86 kB
/* * (c) Copyright Darwino Inc. 2014-2017. */ import React, {Component} from "react"; import FieldStatic from './FieldStatic'; class FieldRadioGroup extends Component { renderMultipleRadio(values,val) { const { input, meta, options, disabled, label, inline, ...props} = this.props; const checked = values==val.value return ( <label className={inline?"radio-inline":""} key={val.value} style={inline ? {marginRight:'1em'} : null}> <input type="radio" {...props} checked={checked} disabled={disabled} onChange={(e)=>{ input.onChange(val.value) }} onBlur={(e)=>{ input.onBlur(values) }}/> {val.label!==undefined ? val.label : val.value} </label> ) } render() { const { input, options, inline, readOnly, ...props} = this.props; if(readOnly) { const { inline, ...roprops } = this.props; return (<FieldStatic {...roprops}/>); } const values = input.value return ( <div className="radio"> {options && options.map(val => { if(!(typeof(val)==="object")) val = {value:val,label:val}; if(inline) { return ( this.renderMultipleRadio(values,val) ) } else { return ( <div className="radio" key={val.value}> {this.renderMultipleRadio(values,val)} </div> ) } })} </div> ) } }; export default FieldRadioGroup