{ this.props.prefix ?
{this.props.prefix} : '' }
{ renderElementInsideLabel ?
:
element }
{ this.props.postfix ?
{this.props.postfix} : '' }
{ isError && this.state.errorMessage ?
{this.state.errorMessage}
: '' }
}
})
export let FormRow = React.createClass({
_fieldRequiredText: 'This field is required',
propTypes: {
label: React.PropTypes.oneOfType([React.PropTypes.string, React.PropTypes.element])
// helper: React.PropTypes.html,
},
getInitialState: function() {
return {
isError: false,
errorMessage: null,
}
},
showError: function(text) {
this.setState({
isError: true,
errorMessage: text,
});
},
showRequiredError: function() {
this.showError(this._fieldRequiredText);
},
clearError: function(text) {
this.setState({
isError: false,
errorMessage: ''
});
},
getValue: function() {
return this.refs.field.getValue();
},
getSelectedElement: function() {
return this.refs.field.getSelectedElement();
},
focus: function() {
this.refs.field.focus();
},
render: function() {
const fieldProps = Object.assign({}, this.props),
elementId = formFieldId(),
renderLabelInFormField = formFieldNestedLabelTypes.includes(this.props.type);
if (!renderLabelInFormField) {
delete fieldProps.label;
}
delete fieldProps.helper;
return
{ this.props.label && !renderLabelInFormField ?
: '' }
{ !this.state.isError && this.props.helper ?
{this.props.helper}
: '' }
{ this.state.isError ?
{this.state.errorMessage}
: '' }
}
})