Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a Cancel button in Bootstrap

I have the following Bootstrap markup:

<!-- Text input-->
<div class="form-group">
  <label class="col-md-4 control-label" for="username">Username</label>
  <div class="col-md-4">
  <input id="username" name="username" type="text" placeholder="" class="form-control input-md" required="" maxlength="8" value="">
  </div>
</div>

<!-- Button (Double) -->
<div class="form-group">
  <label class="col-md-4 control-label" for="submit"></label>
  <div class="col-md-8">
    <button id="submit" name="submit" class="btn btn-primary" value="1">Create Profile</button>
    <button id="cancel" name="cancel" class="btn btn-default" value="1">Cancel</button>
  </div>
</div>

When I click the Create Profile button the form works fine letting me know that certain fields are "Required". But when I click the Cancel button I cannot leave the form due to incomplete required fields.

Is there a form cancel button capability in Bootstrap?

like image 697
H. Ferrence Avatar asked Nov 02 '15 19:11

H. Ferrence


People also ask

How do I close a Bootstrap button?

Creating close button in Bootstrap 4The close button can be added by using the simple markup with CSS class. The main container for close button is the <button> tag with . close class.

What is the use of Cancel button?

What does the Cancel button do exactly? It dismisses the user's current screen and brings them back to their previous screen. This dismissive button is a safeguard to prevent unwanted changes to the system.


2 Answers

Change your code to the following:

<!-- Button (Double) -->
<div class="form-group">
  <label class="col-md-4 control-label" for="submit"></label>
  <div class="col-md-8">
    <button id="submit" name="submit" class="btn btn-primary" value="1">Create Profile</button>
    <a href="/link-to/whatever-address/" id="cancel" name="cancel" class="btn btn-default">Cancel</a>
  </div>
</div>
like image 58
Adrian Chrostowski Avatar answered Sep 28 '22 13:09

Adrian Chrostowski


simply set the type attribute to reset as shown below;

<button type="reset" class="btn btn-default pull-right">Cancel</button>

like image 31
Emmanuel Aninze Avatar answered Sep 28 '22 11:09

Emmanuel Aninze