title: creating custom widget with flask wtforms
body: <p>I am strugling to find resources that explain how to create custom widget with wtforms. I want to display a list of toggle buttons. So far I ve been able to create a list of checkboxes with </p>
  
  <pre><code>SelectMultipleFields:
    class PrecisionForm(FlaskForm):
      phone_number = StringField('Phone number', [validators.Length(min=4, max=25)])
      contact_emails = SelectMultipleField(
          'Contact emails',
          [at_least_one],
          choices=[],
          option_widget=widgets.CheckboxInput(),
          widget=widgets.ListWidget(prefix_label=False)
       )
  </code></pre>
  
  <p>but now I want to modify my <code>widget.CheckBoxInput()</code> with my custom widget looking like :</p>
  
  <p><code>&lt;label class='switch'&gt; &lt;input type='checkbox'&gt;&lt;span class='slider round'&gt;&lt;/span&gt;&lt;/label&gt;</code></p>
  
  <p>I would be very grateful if someone could explain step by step how to do that.</p>
  
  <p>--UPDATE--</p>
  
  <p>I found a way to achieve what I wanted to do but it seems pretty bad :</p>
  
  <pre><code>class ToggleButtonWidget(object):
      def __call__(self, field):
          html = '&lt;label class="switch"&gt;&lt;input type="checkbox" id={} name={} value={}&gt;&lt;span class="slider round"&gt;&lt;/span&gt;&lt;/label&gt;'.format(field.id, field.name, field.label.__dict__['text'])
          return HTMLString(html)
  </code></pre>
  
  <p>especially this part : <code>field.label.__dict__['text']</code> that I use to set the value of my checkbox (the field object from wtforms has no attribute value). Is there a better way ?</p>