Skip to content

Commit

Permalink
Merge pull request #4667 from keystonejs/empty-relationship-fix
Browse files Browse the repository at this point in the history
Fix for empty relationships submitting no value
  • Loading branch information
JedWatson authored Jun 22, 2018
2 parents 96f81c3 + 3953813 commit a726d4a
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion fields/types/relationship/RelationshipField.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,16 +190,21 @@ module.exports = Field.create({
},

renderSelect (noedit) {
const inputName = this.getInputName(this.props.path);
const emptyValueInput = (this.props.many && (!this.state.value || !this.state.value.length))
? <input type="hidden" name={inputName} value="" /> : null;
return (
<div>
{/* This input ensures that an empty value is submitted when no related items are selected */}
{emptyValueInput}
{/* This input element fools Safari's autocorrect in certain situations that completely break react-select */}
<input type="text" style={{ position: 'absolute', width: 1, height: 1, zIndex: -1, opacity: 0 }} tabIndex="-1"/>
<Select.Async
multi={this.props.many}
disabled={noedit}
loadOptions={this.loadOptions}
labelKey="name"
name={this.getInputName(this.props.path)}
name={inputName}
onChange={this.valueChanged}
simpleValue
value={this.state.value}
Expand Down

0 comments on commit a726d4a

Please sign in to comment.