user977828
user977828

Reputation: 7679

Bootstrap Toggle avoid form submission

I used bootstrap toggle in the following way, but by changing from YES to NO it submit the from.

<B>Do you want?</B>
<div class="btn-group btn-toggle"> 
  <button class="btn btn-xs btn-default">Yes</button>
  <button class="btn btn-xs btn-primary active">No</button>
</div>                           

The form code is shown bellow:

{% extends 'base.html' %}

{% block body %}

  <div class="row clearfix">
          <div class="col-md-6 column">
                  <form class="form-horizontal" action="{{ url_for('tsnps')}}" method="POST" role="form">
                  {{ fform.hidden_tag() }} 
                          <div class="form-group">
                                  <div class="col-sm-5">
                                          {{ fform.start_pos(class="form-control", placeholder="Start position e.g. 1", type="number")}}
                                  </div>

                                  <div class="col-sm-5">
                                          {{ fform.end_pos(class="form-control", placeholder="End position e.g. 1000", type="number")}}
                                  </div>
                          </div>  

                          <B>Do you want?</B>
                          <div class="btn-group btn-toggle"> 
                            <button class="btn btn-xs btn-default">Yes</button>
                            <button class="btn btn-xs btn-primary active">No</button>
                          </div>

                          <div class="form-group">
                                  <div class="col-sm-10">
                                          <div class="checkbox">
                                                  <label><input type="checkbox" /> Remember me</label>
                                          </div>
                                  </div>
                          </div>
                          <div class="form-group">
                                  <div class="col-sm-10">
                                          <button type="submit" class="btn btn-default">Send</button>
                                  </div>
                          </div>
                  </form>
          </div>
  </div>
{% endblock %}

How is it possible only to save the value (YES or NO) and avoid the form submission?

Upvotes: 1

Views: 1642

Answers (1)

davidism
davidism

Reputation: 127210

Change the button's type to "button". The default type is "submit" (at least on some browsers), which will act like a submit input.

<button type="button" class="btn btn-xs btn-default">Yes</button>

Upvotes: 2

Related Questions