Allows setting custom id and class

This commit is contained in:
Vlad
2018-02-06 20:31:00 -05:00
parent 243ed9d61b
commit a8305adf8d

View File

@ -2,6 +2,7 @@ import React from 'react';
const FormFieldText = React.createClass({ const FormFieldText = React.createClass({
render() { render() {
const name = this.props.field.name || null;
const item = this.props.item || {}; const item = this.props.item || {};
let value; let value;
let defaultValue; let defaultValue;
@ -17,6 +18,16 @@ const FormFieldText = React.createClass({
defaultValue = this.props.field.defaultValue; defaultValue = this.props.field.defaultValue;
} }
let id = this.props.field.id || null;
if (!id && this.props.field.name) {
id = `field_${this.props.field.name}`;
}
let className = this.props.field.class || null;
if (!className && !this.props.field.size) {
className = 'regular-text';
}
return ( return (
<input <input
type="text" type="text"
@ -25,14 +36,14 @@ const FormFieldText = React.createClass({
? this.props.field.disabled(this.props.item) ? this.props.field.disabled(this.props.item)
: false : false
} }
className={(this.props.field.size) ? '' : 'regular-text'} className={className}
size={ size={
(this.props.field.size !== 'auto' && this.props.field.size > 0) (this.props.field.size !== 'auto' && this.props.field.size > 0)
? this.props.field.size ? this.props.field.size
: false : false
} }
name={this.props.field.name} name={name}
id={`field_${this.props.field.name}`} id={id}
value={value} value={value}
defaultValue={defaultValue} defaultValue={defaultValue}
placeholder={this.props.field.placeholder} placeholder={this.props.field.placeholder}