Answers.Body: <p>100% untested and I haven't had coffee yet, but I think it'd be a combination of a few things.</p>
  
  <p>1) Having your plugin override <a href="http://buildwithcraft.com/classreference/etc/components/BaseSavableComponentType" rel="nofollow">BaseSavableComponentType's</a> <a href="http://buildwithcraft.com/classreference/etc/components/BaseSavableComponentType#getSettingsModel-detail" rel="nofollow">getSettingsModel()</a> so that it returned a MyPluginSettingsModel().</p>
  
  <p>2) Have MyPluginSettingsModel override the rules method to do something like:</p>
  
  <pre><code>public function rules()
  {
      $rules = parent::rules();
  
      $rules[] = array('myStartDate, myEndDate', 'required');
  
      return $rules;
  }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-13T14:59:45.520Z
Answers.LastActivityDate: 2015-04-13T14:59:45.520Z
Answers.UserDisplayName: Brad Bell
Body: <p>From <a href="https://experiencehq.net/blog/the-definitive-guide-to-validation-in-craft-part-2-attributetypes" rel="nofollow">this incredibly helpful validation article(s)</a>, I found that:</p>
  
  <blockquote>
    <p>AttributeType::Mixed does not apply any validation rules</p>
  </blockquote>
  
  <p>Ok cool. I am using two fields that are DateTime fields, but due to a known bug, a work-around is to make the field type <code>Mixed</code>. </p>
  
  <p>Everything is working 100% - and I can't thank the community for their help. </p>
  
  <p>However, in my settings page, I would (like) to have my start date (Mixed) and end date (Mixed) fields required. </p>
  
  <p>This isn't a make-or-break deal, just curious if there is a way.</p>
  
  <p><strong>MyPlugin.php</strong></p>
  
  <pre><code>....
  'myStartDate' =&gt; array(AttributeType::Mixed, 'required' =&gt; true),
  'myEndDate' =&gt; array(AttributeType::Mixed, 'required' =&gt; true),
  ....
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <p>Hi Brad, they are attribute settings. I've updated to show the file(s) below. Thank you for your time!</p>
  
  <p><strong>_settings.html</strong></p>
  
  <pre><code>....
  {{
      forms.dateField({
          'label': "Start Date"|t,
          'instructions': "What week do we start?"|t,
          'required': true,
          'id': 'myStartDate',
          'name': 'myStartDate',
          'placeholder': 'mm/dd/yyyy',
          'value': settings.myStartDate,
          'errors': settings.getErrors('myStartDate')
      })
  }}
  ....
  </code></pre>
  
  <p><strong>MyPlugin.php</strong></p>
  
  <pre><code>public function defineSettings()
  {
      return array('myStartDate' =&gt; array(AttributeType::Mixed, 'required' =&gt; true),
                   'myEndDate' =&gt; array(AttributeType::Mixed, 'required' =&gt; true)
          );
  }
  </code></pre>
  
  <p>If I make the field type a DateTime, then the required works. Maybe it's all part of the same bug. If it is, that's cool. It's not a big deal I'm more curious if I'm doing something wrong for the field type since <code>::Mixed</code> does not apply any validation rules.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-04-13T02:28:09.690Z
Comments.Text: Are those settings attributes or proper model attributes?
Comments.UserDisplayName: Brad Bell
Tags: <plugin-development><validation>
Title: How to make a mixed field type required
ThreadText: # How to make a mixed field type required
  
  (Asked by: username_0 on 2015-04-12)
  
  From [this incredibly helpful validation article(s)](https://experiencehq.net/blog/the-definitive-guide-to-validation-in-craft-part-2-attributetypes), I found that:
  
  > AttributeType::Mixed does not apply any validation rules
  
  Ok cool. I am using two fields that are DateTime fields, but due to a known bug, a work-around is to make the field type `Mixed`.
  
  Everything is working 100% - and I can't thank the community for their help.
  
  However, in my settings page, I would (like) to have my start date (Mixed) and end date (Mixed) fields required.
  
  This isn't a make-or-break deal, just curious if there is a way.
  
  **MyPlugin.php**
  
  ```
  ....
  'myStartDate' => array(AttributeType::Mixed, 'required' => true),
  'myEndDate' => array(AttributeType::Mixed, 'required' => true),
  ....
  
  ```
  
  **EDIT**
  
  Hi username_1, they are attribute settings. I've updated to show the file(s) below. Thank you for your time!
  
  **\_settings.html**
  
  ```
  ....
  {{
      forms.dateField({
          'label': "Start Date"|t,
          'instructions': "What week do we start?"|t,
          'required': true,
          'id': 'myStartDate',
          'name': 'myStartDate',
          'placeholder': 'mm/dd/yyyy',
          'value': settings.myStartDate,
          'errors': settings.getErrors('myStartDate')
      })
  }}
  ....
  
  ```
  
  **MyPlugin.php**
  
  ```
  public function defineSettings()
  {
      return array('myStartDate' => array(AttributeType::Mixed, 'required' => true),
                   'myEndDate' => array(AttributeType::Mixed, 'required' => true)
          );
  }
  
  ```
  
  If I make the field type a DateTime, then the required works. Maybe it's all part of the same bug. If it is, that's cool. It's not a big deal I'm more curious if I'm doing something wrong for the field type since `::Mixed` does not apply any validation rules.
  
  **Tags:** plugin-development, validation
  
  > **Comments:**
  > **username_1**: Are those settings attributes or proper model attributes?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-04-13. Score: 1
  
  100% untested and I haven't had coffee yet, but I think it'd be a combination of a few things.
  
  1) Having your plugin override [BaseSavableComponentType's](http://buildwithcraft.com/classreference/etc/components/BaseSavableComponentType) [getSettingsModel()](http://buildwithcraft.com/classreference/etc/components/BaseSavableComponentType#getSettingsModel-detail) so that it returned a MyPluginSettingsModel().
  
  2) Have MyPluginSettingsModel override the rules method to do something like:
  
  ```
  public function rules()
  {
      $rules = parent::rules();
  
      $rules[] = array('myStartDate, myEndDate', 'required');
  
      return $rules;
  }
  
  ```
  
  
  ---
  
  