Answers.Body: <blockquote>
    <p>I can mark the field as required in the layout builder, but that is for the CP only I think.</p>
  </blockquote>
  
  <p>Nope... marking the field as required makes it required globally (regardless of if it's coming from the control panel or the front-end).</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-06T03:54:44.577Z
Answers.Text: Ok I've tested it, is there a friendly way to pass a null value to commerce?  I'm getting caught in this when I pass nothing to commerce:
  `throw new Exception(Craft::t('Not a purchasable ID'));`
Answers.UserDisplayName: Damon
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-06T03:21:20.947Z
Answers.LastActivityDate: 2016-01-06T03:21:20.947Z
Answers.UserDisplayName: Brad Bell
Body: <p>I have a drop-down of variants of a product. For example t-shirts:</p>
  
  <pre><code>{% for purchasable in product.variants %}
      &lt;option value=""&gt;Select&lt;/option&gt;
      &lt;option {% if purchasable.stock &lt;= 0 and purchasable.unlimitedStock == false %}disabled {% endif %} value="{{ purchasable.purchasableId }}"&gt;
          {{ purchasable.title }} &amp;ndash; {{ purchasable.price|currency(cart.currency) }}
      &lt;/option&gt;
  {% endfor %}
  </code></pre>
  
  <p>As you can see I have "Select" as the default option, and it has no value. I can validate the form client side no problem, but I am curious if there is a way to designate that fields as required from the server-side? I can mark the field as required in the layout builder, but that is for the CP only I think.</p>
  
  <p>If I do not choose an option, I get this error:</p>
  
  <pre><code>Craft\Exception 
  Not a purchasable ID
  </code></pre>
  
  <p>Which makes perfect sense since I am not passing it a valid purchasable element.</p>
  
Tags: <validation><plugin-craftcommerce>
Title: How can I make a product field required?
ThreadText: # How can I make a product field required?
  
  (Asked by: username_0 on 2016-01-06)
  
  I have a drop-down of variants of a product. For example t-shirts:
  
  ```
  {% for purchasable in product.variants %}
      <option value="">Select</option>
      <option {% if purchasable.stock <= 0 and purchasable.unlimitedStock == false %}disabled {% endif %} value="{{ purchasable.purchasableId }}">
          {{ purchasable.title }} &ndash; {{ purchasable.price|currency(cart.currency) }}
      </option>
  {% endfor %}
  
  ```
  
  As you can see I have "Select" as the default option, and it has no value. I can validate the form client side no problem, but I am curious if there is a way to designate that fields as required from the server-side? I can mark the field as required in the layout builder, but that is for the CP only I think.
  
  If I do not choose an option, I get this error:
  
  ```
  Craft\Exception 
  Not a purchasable ID
  
  ```
  
  Which makes perfect sense since I am not passing it a valid purchasable element.
  
  **Tags:** validation, plugin-craftcommerce
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-01-06. Score: 2 | Accepted answer
  
  > I can mark the field as required in the layout builder, but that is for the CP only I think.
  
  Nope... marking the field as required makes it required globally (regardless of if it's coming from the control panel or the front-end).
  
  > **Comments:**
  > **username_0**: Ok I've tested it, is there a friendly way to pass a null value to commerce?  I'm getting caught in this when I pass nothing to commerce: `throw new Exception(Craft::t('Not a purchasable ID'));`  
  
  ---
  
  