HTML inline forms with buttons - html

Here is my HTML code:
<div class="text-right">
<form method="post" action="create_car_type.html">
<button type="submit" value=4 class="btn btn-danger ml-2 mr-3" title="Create a car type">
Create a type
</button>
</form>
<form method="post" action="delete_car_type.html">
<button type="submit" value=3 class="btn btn-warning ml-2 mr-3">
Delete a type
</button>
</form>
</div>
These two buttons are inside forms, which are inside a div. They are right aligned in this div, but I would like to display them inline. The way they are displayed currently is that one places above the other, which is something I want to avoid. Should I include something like display: inline somewhere? Where should this go?

add style="display: inline-block;" to form tags
<div class="text-right">
<form method="post" action="create_car_type.html" style="display: inline-block;">
<button type="submit" value=4 class="btn btn-danger ml-2 mr-3" title="Create a car type">
Create a type
</button>
</form>
<form method="post" action="delete_car_type.html" style="display: inline-block;">
<button type="submit" value=3 class="btn btn-warning ml-2 mr-3">
Delete a type
</button>
</form>
</div>

you can use a display: flex or display: inline-flex to your main div tag and this is the most easy way to make something inline. something like this
.text-right{
display: flex;
gap: 10px; /*also you can use gap to give a space between them*/
}
<div class="text-right">
<form method="post" action="create_car_type.html">
<button type="submit" value=4 class="btn btn-danger ml-2 mr-3" title="Create a car type">
Create a type
</button>
</form>
<form method="post" action="delete_car_type.html">
<button type="submit" value=3 class="btn btn-warning ml-2 mr-3">
Delete a type
</button>
</form>
</div>

Related

How to change the button position

I want to change save button will be first then prev button should be come
<input type="button" class="btn btn-primary float-right mx-3"name="firstprevious" onclick="mprev()" value="Prev">
<input type="submit" class="btn btn-primary float-right order-2"name="register" value="Save">
<div>
<input type="button" class="btn btn-primary pull-right mx-3 prev" name="firstprevious" onclick="mprev()" value="Prev">
<input type="submit" class="btn btn-primary pull-left order-2 save"name="register" value="Save">
</div>
CSS:
div{
display: flex;
}
.save{
order:1;
}
.prev{
order:2;
}
Try to add pull-left to your save button and pull-right to your prev button. Please let me know if it's work. Thanks
<input type="button" class="btn btn-primary pull-right mx-3" name="firstprevious" onclick="mprev()" value="Prev">
<input type="submit" class="btn btn-primary pull-left order-2"name="register" value="Save">

Label smaller than button in Bootstrap button group

I found some come to make a button that is also an input file with a label :
<label>
Import
<input type="file" hidden>
</label>
So I put in on the toolbar on my project where I'm using a button group :
<div class="btn-toolbar" role="toolbar">
<div class="btn-group mr-2" role="group">
<button class="btn btn-primary" (click)="newNetwork()">New network</button>
<label class="btn btn-primary">
Import
<input type="file" (change)="import($event.target.files)" hidden>
</label>
<button class="btn btn-primary" (click)="export()">Export</button>
</div>
<div class="btn-group mr-2" role="group">
<button class="btn btn-primary" (click)="addElement('station')">Add station</button>
<button class="btn btn-primary" (click)="addElement('shed')">Add shed</button>
<button class="btn btn-primary" (click)="addElement('bridge')">Add bridge</button>
</div>
<div class="btn-group" role="group">
<button class="btn"
[ngClass]="{'btn-primary': !linking, 'btn-warning': linking}"
(click)="link()">
Add link
</button>
<button class="btn"
[ngClass]="{'btn-primary': !editing, 'btn-warning': editing}"
(click)="edit()">
Edit
</button>
<button class="btn"
[ngClass]="{'btn-primary': !removing, 'btn-warning': removing}"
(click)="remove()">
Remove
</button>
</div>
</div>
The thing the label is actually a bit shorter than other buttons.
I tried to fix it's height :
<label style="height: 101%" class="btn btn-primary">
It works but now the text isn't vertically centered !
Is there a way to make it look like a normal button ?
You can remove the margin of that label like this:
(I would not recommend inline css).
.export {
margin: 0px;
}
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
</head>
<div class="btn-toolbar" role="toolbar">
<div class="btn-group mr-2" role="group">
<button class="btn btn-primary" (click)="newNetwork()">New network</button>
<label class="btn btn-primary export">
Import
<input type="file" (change)="import($event.target.files)" hidden>
</label>
<button class="btn btn-primary " (click)="export()">Export</button>
</div>
<div class="btn-group mr-2" role="group">
<button class="btn btn-primary" (click)="addElement('station')">Add station</button>
<button class="btn btn-primary" (click)="addElement('shed')">Add shed</button>
<button class="btn btn-primary" (click)="addElement('bridge')">Add bridge</button>
</div>
<div class="btn-group" role="group">
<button class="btn"
[ngClass]="{'btn-primary': !linking, 'btn-warning': linking}"
(click)="link()">
Add link
</button>
<button class="btn"
[ngClass]="{'btn-primary': !editing, 'btn-warning': editing}"
(click)="edit()">
Edit
</button>
<button class="btn"
[ngClass]="{'btn-primary': !removing, 'btn-warning': removing}"
(click)="remove()">
Remove
</button>
</div>
</div>

Laravel - How to show edit and delete button on 1 row from two forms?

I have two forms with at the bottom respectively a button to update and to delete the data. I want to place the buttons on 1 line.
The problem is when I am using "div class row" to place the button on the same row and leave them open between the two forms (see code)
my data is deleted when I press de update button. If I close the "div class row" then naturally the buttons are working perfectly but they are now on different rows.
How can I fix this? Thanks for the help.
## Leave the class open ==> Update Delete
<form method="POST" action="/tasks/{{ $event->id }}" >
#csrf
#method('PATCH')
...
<div class="row">
<div class="col-4 offset-1">
<button type="submit" class="btn btn-block btn-primary">Update</button>
</div>
</form>
<form action="/tasks/{{$task->id}}" method="post">
#csrf
#method('DELETE')
<div class="col-4 offset-2">
<button type="submit" class="btn btn-block btn-danger">Delete</button>
</div>
</div>
</form>
## Leave the class open ==> Update
Delete
<form method="POST" action="/tasks/{{ $event->id }}" >
#csrf
#method('PATCH')
...
<div class="col-4 offset-1">
<button type="submit" class="btn btn-block btn-primary">Update</button>
</div>
</form>
<form action="/tasks/{{$task->id}}" method="post">
#csrf
#method('DELETE')
<div class="col-4 offset-6">
<button type="submit" class="btn btn-block btn-danger">Delete</button>
</div>
</div>
</form>
Yeah, this is a tricky one. Have you considered using JavaScript for the delete button?
Change the button type to button and add the onclick attribute to the button and submit the delete form on click.
<form method="POST" action="/tasks/{{ $event->id }}" >
#csrf
#method('PATCH')
...
<div class="row">
<div class="col-4 offset-1">
<button type="submit" class="btn btn-block btn-primary">Update</button>
</div>
<div class="col-4 offset-2">
<button type="button" class="btn btn-block btn-danger"
onclick="event.preventDefault();
document.getElementById('delete-task-form').submit();"
">Delete</button>
</div>
</div>
</form>
<form action="/tasks/{{$task->id}}" id="delete-task-form" method="post">
#csrf
#method('DELETE')
</form>
Create a class with display flex and align child accordingly to what you wish to achieve.
Here's some lecture:
https://css-tricks.com/quick-whats-the-difference-between-flexbox-and-grid/
You can just insert all the forms inside the div. So instead of wrapping them with form tag you want to wrap them with div, and put the form inside the div. That way you can arrange the button with col-md class more easily.
<div class="col-4 offset-6">
<form action="/tasks/{{$task->id}}" method="post">
#csrf
#method('DELETE')
<button type="submit" class="btn btn-block btn-danger">Delete</button>
</form>
</div>

Align form and buttons inside div

I tried adding container and/or row div classes and also tried to add left position for all. How can I align these elements in a row with no css or minimal css changes ?
<div class="container">
<span class="input-group-btn">
<button class="btn btn-default" type="button">Go!</button>
<button class="btn btn-danger" type="button">Stop - X</button>
</span>
<input type="text" class="form-control">
<form method="post" action="/controller/new" class="button_to">
<input value="New" type="submit" />
</form>
</div>
I am expecting to have [Go][Stop][ .... ][Submit] in same row. Link for the demo repl
Try to add this piece of css:
form {
display: inline;
}
<form> - is a block level element, so it breaks lines before and after itself. You have to make it behave as if it is an inline element to overcome the issue.
form {
display: inline;
}
<div class="container">
<span class="input-group-btn">
<button class="btn btn-default" type="button">Go!</button>
<button class="btn btn-danger" type="button">Stop - X</button>
</span>
<input type="text" class="form-control">
<form method="post" action="/controller/new" class="button_to">
<input value="New" type="submit" />
</form>
</div>
Your form is set to display: block; change it to display: inline-block; and it will work like charm.
form{
display: inline-block;
}
<div class="container">
<span class="input-group-btn">
<button class="btn btn-default" type="button">Go!</button>
<button class="btn btn-danger" type="button">Stop - X</button>
</span>
<input type="text" class="form-control">
<form method="post" action="/controller/new" class="button_to">
<input value="New" type="submit" />
</form>
</div>
Add display: inline-block to your form (.button_to):
.button_to {
display: inline-block;
}
You can also remove that styles with position: left because it's unnecessary.

How to create a button group with css bootstrap?

I am trying to create a button group with css bootstrap framework.
I was able to create button-group with no problem. But, one of my buttons should be wrapped with a form to perform post request when clicking it.
Here is my code
<div class="btn-group btn-group-xs pull-right" role="group">
<a href="/salecategories" class="btn btn-primary" title="Show all salecategories">
<span class="glyphicon glyphicon-th-list" aria-hidden="true"></span>
</a>
<a href="/salecategories/2/edit" class="btn btn-primary" title="Edit SaleCategory">
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
</a>
<form method="POST" action="/salecategories/salecategory/2" accept-charset="UTF-8" style="display: inline;" novalidate="novalidate">
<input name="_method" value="DELETE" type="hidden">
<input name="_token" value="8123RX6LbCpxo7LDdp3eettEXGzdfbS9gvzjbbWP" type="hidden">
<button type="submit" class="btn btn-danger btn-xs" title="Delete SaleCategory" onclick="return confirm("Confirm delete?")" id="sometest">
<span class="glyphicon glyphicon-trash" aria-hidden="true" title="Delete SaleCategory"></span>
</button>
</form>
</div>
The above code work but the "red button" is not aligned with the rest at the following screenshot shows.
How can I align the "red" button with the other two?
Here is a jsfiddler to allow you to tinker with the code. Note, the fiddler shows the button now connected but the screenshot shows not aligned because I am using a different font for my app.
You can wrap the whole button group in the form. That way you can keep the three buttons together side by side.
<form action="/salecategories/salecategory/2">
<div class="btn-group btn-group-xs" role="group">
Show all
Edit
<button type="submit" class="btn btn-primary">Delete</button>
</div>
</form>