Answers.Body: <p>Copying from the widgets settings I made something that sort of works: </p>
  
  <p>Define the setting to be type mixed: </p>
  
  <pre><code>protected function defineSettings()
  {
      return array(
                   'jobsemail' =&gt; array(AttributeType::Mixed, 'required'=&gt;false),
                   );
  }
  </code></pre>
  
  <p>Then create a settings.html like this: </p>
  
  <pre><code>{% import "_includes/forms" as forms %}
  
  {% set userInput %}
      &lt;div class="select"&gt;
          &lt;select id="jobsemail" name="jobsemail"&gt;
            &lt;option value=""&gt;No one&lt;/option&gt;
              {% for user in craft.users.group('Admin') %}
            &lt;option value="{{ user.id }}"{% if user.id == settings.jobsemail %} selected{% endif %}&gt;{{ user.name|t }}&lt;/option&gt;
              {% endfor %}
          &lt;/select&gt;
      &lt;/div&gt;
  {% endset %}
  
  {{ forms.field({
      label: "Email recipient"|t,
      instructions: "This person gets emailed when new jobs are added"|t,
      id: 'jobsemail',
  }, userInput) }}
  </code></pre>
  
  <p>This gives you a basic SELECT drop-down list. It's ok here, because the number of admin users is low. It would be less suitable if there were 100s of users. </p>
  
  <p>Is a better solution with a real pop-up element picker would be nice!</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-02-18T14:42:21.023Z
Answers.LastActivityDate: 2015-02-18T14:42:21.023Z
Answers.UserDisplayName: gromgull
Body: <p>I'd like to be able to select a user for a settings field for my plugin. </p>
  
  <p>Is there a settings AttributeType that matches users? And a corresponding forms template for picking a user? </p>
  
  <p>(also interesting would be picking assets/elements from a certain section)</p>
  
Tags: <plugin-development><users><form><settings>
Title: Plugin-settings form field for chosing a user?
ThreadText: # Plugin-settings form field for chosing a user?
  
  (Asked by: username_0 on 2015-02-18)
  
  I'd like to be able to select a user for a settings field for my plugin.
  
  Is there a settings AttributeType that matches users? And a corresponding forms template for picking a user?
  
  (also interesting would be picking assets/elements from a certain section)
  
  **Tags:** plugin-development, users, form, settings
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2015-02-18. Score: 2
  
  Copying from the widgets settings I made something that sort of works:
  
  Define the setting to be type mixed:
  
  ```
  protected function defineSettings()
  {
      return array(
                   'jobsemail' => array(AttributeType::Mixed, 'required'=>false),
                   );
  }
  
  ```
  
  Then create a settings.html like this:
  
  ```
  {% import "_includes/forms" as forms %}
  
  {% set userInput %}
      <div class="select">
          <select id="jobsemail" name="jobsemail">
            <option value="">No one</option>
              {% for user in craft.users.group('Admin') %}
            <option value="{{ user.id }}"{% if user.id == settings.jobsemail %} selected{% endif %}>{{ user.name|t }}</option>
              {% endfor %}
          </select>
      </div>
  {% endset %}
  
  {{ forms.field({
      label: "Email recipient"|t,
      instructions: "This person gets emailed when new jobs are added"|t,
      id: 'jobsemail',
  }, userInput) }}
  
  ```
  
  This gives you a basic SELECT drop-down list. It's ok here, because the number of admin users is low. It would be less suitable if there were 100s of users.
  
  Is a better solution with a real pop-up element picker would be nice!
  
  
  ---
  
  