NumberField.js 1.8 KB
import React,{PropTypes} from 'react';
import ReactDOM from 'react-dom';  
import cx from 'classnames';
import s from '../FormRender.scss';


class NumberField extends React.Component {
    constructor(props) {
        super(props);    
        this.transformationNum=this.transformationNum.bind(this);
    }
    static propTypes = {    
        formField:PropTypes.object,
        field:PropTypes.object,
        validateState:PropTypes.string,
        inlineFlag:PropTypes.bool
    } 
    static defaultProps={
        inlineFlag:false,
        validateState:''
    }
    transformationNum(e){
        const {field}=this.props;
        console.log(e.target.value);
        field.onChange(parseFloat(e.target.value));
    }
    render(){  
        const {formField,validateState,inlineFlag,field,type}=this.props,self=this; 
        const options=JSON.parse(formField.options); 
        return( 
            <div className={cx(s.field_wrap,'form-group',{
                'has-success':validateState=='success',
                'has-warning':validateState=='warning',
                'has-error':validateState=='error',
                'row':inlineFlag
            })}> 
                <label className={cx('control-label',{
                    'col-sm-3':inlineFlag
                })}>{formField.display_name}</label>
                <div className={cx(s.input_wrap,{
                    'col-sm-9':inlineFlag
                })} >
                    <input type="number" name={formField.name} className={cx('form-control')}  placeholder={options.tooltip} 
                    onChange={this.transformationNum}  disabled={'readOnly'==type} value={field.value} /> 
                    <span className={cx(s.input_help,'help-block')}><small>{field.touched?field.error:''}</small></span>
                </div>
            </div> 
        )
    }
}



export default NumberField;