Include checkbox for planning fields

This commit is contained in:
Tom Russell 2019-01-19 16:54:20 +00:00
parent 4e6d589891
commit 0c8dc94cb1
2 changed files with 35 additions and 2 deletions

View File

@ -53,6 +53,7 @@ class EditForm extends Component {
this.state.like = this.props.like || undefined; this.state.like = this.props.like || undefined;
this.handleChange = this.handleChange.bind(this); this.handleChange = this.handleChange.bind(this);
this.handleCheck = this.handleCheck.bind(this);
this.handleLike = this.handleLike.bind(this); this.handleLike = this.handleLike.bind(this);
this.handleSubmit = this.handleSubmit.bind(this); this.handleSubmit = this.handleSubmit.bind(this);
this.handleUpdate = this.handleUpdate.bind(this); this.handleUpdate = this.handleUpdate.bind(this);
@ -73,6 +74,21 @@ class EditForm extends Component {
if (name === 'location_postcode' && value !== null) { if (name === 'location_postcode' && value !== null) {
value = value.toUpperCase(); value = value.toUpperCase();
} }
this.setState({
[name]: value
});
}
/**
* Handle changes on checkboxes
* - e.g. input[type=checkbox]
*
* @param {DocumentEvent} event
*/
handleCheck(event) {
const target = event.target;
const value = target.checked;
const name = target.name;
this.setState({ this.setState({
[name]: value [name]: value
@ -208,7 +224,8 @@ class EditForm extends Component {
return <MultiTextInput {...props} handleChange={this.handleUpdate} return <MultiTextInput {...props} handleChange={this.handleUpdate}
value={this.state[props.slug]} key={props.slug} /> value={this.state[props.slug]} key={props.slug} />
case "checkbox": case "checkbox":
return null // TODO checkbox input return <CheckboxInput {...props} handleChange={this.handleCheck}
value={this.state[props.slug]} key={props.slug} />
case "like": case "like":
return <LikeButton {...props} handleLike={this.handleLike} return <LikeButton {...props} handleLike={this.handleLike}
value={this.state[props.slug]} key={props.slug} /> value={this.state[props.slug]} key={props.slug} />
@ -240,7 +257,7 @@ const TextInput = (props) => (
<input className="form-control" type="text" <input className="form-control" type="text"
id={props.slug} name={props.slug} id={props.slug} name={props.slug}
value={props.value || ""} value={props.value || ""}
maxlength={props.max_length} maxLength={props.max_length}
disabled={props.disabled} disabled={props.disabled}
placeholder={props.placeholder} placeholder={props.placeholder}
onChange={props.handleChange} onChange={props.handleChange}
@ -360,6 +377,21 @@ const NumberInput = (props) => (
</Fragment> </Fragment>
); );
const CheckboxInput = (props) => (
<div class="form-check">
<input className="form-check-input" type="checkbox"
id={props.slug} name={props.slug}
checked={!!props.value}
disabled={props.disabled}
onChange={props.handleChange}
/>
<label htmlFor={props.slug} className="form-check-label">
{props.title}
{ props.tooltip? <Tooltip text={ props.tooltip } /> : null }
</label>
</div>
)
const LikeButton = (props) => ( const LikeButton = (props) => (
<Fragment> <Fragment>
<p className="likes">{(props.value)? props.value : 0} likes</p> <p className="likes">{(props.value)? props.value : 0} likes</p>

View File

@ -17,6 +17,7 @@ form .alert {
} }
.form-check-input { .form-check-input {
margin-top: 0.6rem; margin-top: 0.6rem;
left: 0;
} }
label { label {
margin: 0.5em 0 0; margin: 0.5em 0 0;