Answers.Body: <p>I ran into this a while ago and it drove me nuts. Try adding <code>disabled</code> and <code>selected</code> attributes to your initial option in the select. So in your case <code>&lt;option disabled selected&gt;---&lt;/option&gt;</code>.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-02-17T20:29:33.293Z
Answers.Text: This is perfect, except... once you have selected a different option there is no going back to the `---` one. Probably need javascript for that, but my problem is solved.
Answers.UserDisplayName: Marion Newlevant
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-02-17T19:51:24.903Z
Answers.LastActivityDate: 2016-02-17T19:51:24.903Z
Answers.UserDisplayName: Chase Giunta
Body: <p>How to use select dropdown with entries/saveEntry for an entry field?</p>
  
  <p>I have an entry with a field that is another entry, which I want to update with a form:</p>
  
  <pre><code>&lt;form method="post" accept-charset="UTF-8"&gt;
    {{ getCsrfInput() }}
    &lt;input type="hidden" name="action" value="entries/saveEntry"&gt;
    &lt;input type="hidden" name="entryId" value="{{ entry.id }}"&gt;
    &lt;label&gt;Vendor
      &lt;select name="fields[vendor][]"&gt;
        &lt;option&gt;---&lt;/option&gt;
        {% for v in craft.entries.section('vendors') %}
          &lt;option value="{{v.id}}"&gt;{{v.title}}&lt;/option&gt;
        {% endfor %}
      &lt;/select&gt;
    &lt;/label&gt;
    &lt;input type="submit" value="Submit"/&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>This works fine, except if nothing is selected in the dropdown (<code>&lt;option&gt;---&lt;/option&gt;</code>). In that case, the POST value for <code>fields[vendor][]</code> is <code>---</code>, and I get a SQL foreign key constraint error.</p>
  
  <p>I have also tried <code>&lt;option value=""&gt;---&lt;/option&gt;</code> and <code>&lt;option value="NULL"&gt;---&lt;/option&gt;</code> with no better outcome.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-02-17T19:16:44.477Z
Comments.Text: Been a while since I've dealt with this, but I did come up with this same error. Try adding `selected="selected"` to the option. I think the issue is submitting a field with empty data. The form isn't submitted with that option selected.
Comments.UserDisplayName: Chase Giunta
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-02-17T19:29:10.683Z
Comments.Text: @ChaseGiunta - pretty sure the `selected=selected` only affects which choice is initially selected, and nothing in the post data. In any event, it didn't help (unfortunately)
Comments.UserDisplayName: Marion Newlevant
Tags: <frontend><saveentry>
Title: How to use select dropdown with entries/saveEntry for an entry field?
ThreadText: # How to use select dropdown with entries/saveEntry for an entry field?
  
  (Asked by: username_0 on 2016-02-17)
  
  How to use select dropdown with entries/saveEntry for an entry field?
  
  I have an entry with a field that is another entry, which I want to update with a form:
  
  ```
  <form method="post" accept-charset="UTF-8">
    {{ getCsrfInput() }}
    <input type="hidden" name="action" value="entries/saveEntry">
    <input type="hidden" name="entryId" value="{{ entry.id }}">
    <label>Vendor
      <select name="fields[vendor][]">
        <option>---</option>
        {% for v in craft.entries.section('vendors') %}
          <option value="{{v.id}}">{{v.title}}</option>
        {% endfor %}
      </select>
    </label>
    <input type="submit" value="Submit"/>
  </form>
  
  ```
  
  This works fine, except if nothing is selected in the dropdown (`<option>---</option>`). In that case, the POST value for `fields[vendor][]` is `---`, and I get a SQL foreign key constraint error.
  
  I have also tried `<option value="">---</option>` and `<option value="NULL">---</option>` with no better outcome.
  
  **Tags:** frontend, saveentry
  
  > **Comments:**
  > **username_1**: Been a while since I've dealt with this, but I did come up with this same error. Try adding `selected="selected"` to the option. I think the issue is submitting a field with empty data. The form isn't submitted with that option selected.  
  > **username_0**: @username_1 - pretty sure the `selected=selected` only affects which choice is initially selected, and nothing in the post data. In any event, it didn't help (unfortunately)  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-02-17. Score: 3 | Accepted answer
  
  I ran into this a while ago and it drove me nuts. Try adding `disabled` and `selected` attributes to your initial option in the select. So in your case `<option disabled selected>---</option>`.
  
  > **Comments:**
  > **username_0**: This is perfect, except... once you have selected a different option there is no going back to the `---` one. Probably need javascript for that, but my problem is solved.  
  
  ---
  
  