show a small inline delete button upon button press in ng-bootstrap - html

My Current implementation of what I want is done using ng-bootstrap for Angular4.
Image
As you can see I used the Check box button to display a response from the backend. If you click on the button the x button will be not be shown and it will also hide some other html elements below.
Upon clicked (checked)
I am actually looking to improve the layout, where I wish that the x button would somehow be spanned together for a smooth feeling.
I do not know of any components from Bootstrap4.x or ng-bootstrap itself that could do something.
Any design suggestions or improvements is what I am looking for.
code
<!-- Search Keywords go here -->
<div class="container" *ngIf="Output.length">
<div class="row">
<div class="col-sm-2">
<label class="col-form-label-lg"><b> Search History </b></label>
</div>
<div class="col-sm-10">
<div class="btn-group btn-group-toggle" *ngFor="let keyword of Output; let cbIndex = index">
<label class="btn-primary" ngbButtonLabel>
<input type="checkbox"
ngbButton
#kwCheck
(change)="cbInput= kwCheck.checked; hideKW(cbIndex)"
> {{keyword.kw}}
</label>
<span><button class="btn btn-xs btn-danger"
(click)="deleteKW(keyword.kw); $event.stopPropagation()"
[disabled]=kwCheck.checked
[hidden]="kwCheck.checked">×</button>
</span>
</div>
</div>
</div>
</div>
Output.length is an array of JSON responses from the backend.

There are, at least, two ways that you can do so.
Use btn-group. It is pretty well semantic also, except that you use btn class for the input container which is a not button.
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.1/css/bootstrap.css" rel="stylesheet"/>
<div class="btn-group" role="group" aria-label="Basic example">
<label class="btn d-flex align-items-center bg-primary px-3 mb-0">
<input type="checkbox" class="" id="customCheck1">
<span class="px-1 mb-0" for="customCheck1">Check</span>
</label>
<button type="button" class="btn btn-danger">×</button>
</div>
Use input-group. I prefer this approach because all of the classes have meaning.
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.1/css/bootstrap.css" rel="stylesheet" />
<div class="input-group w-auto">
<label class="d-flex align-items-center w-auto bg-primary px-3 mb-0">
<input type="checkbox" placeholder="Username" aria-label="Username" aria-describedby="basic-addon1">
<span class="pl-2">Check</span>
</label>
<div class="input-group-prepend">
<button class="btn btn-danger" type="button">×</button>
</div>
</div>
Update
In order to hide the checkbox's tick mark, use btn-group-toggle. It is the same method that bootstrap does.
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.1/css/bootstrap.css" rel="stylesheet" />
<div class="input-group w-auto ">
<div class="btn-group-toggle" data-toggle="buttons">
<label class="btn btn-primary" style="border-radius: 0;">
<input type="checkbox" autocomplete="off"> Check
</label>
</div>
<div class="input-group-prepend">
<button class="btn-danger btn" id="basic-addon1">×</button>
</div>
</div>
As far as i know, there is no way to reset the border to zero. So, you have to use custom CSS.*
https://codepen.io/anon/pen/qKOdJv?editors=1000

Related

Bootstrap Styling is not working as expected

In my current ASP.Net core I am trying to do the boot strap styling for search component on the page. I want the UI to look like
where the label/input box and the Search button to appear in the middle of the screen and the Create New To show in the same row but to appear right side of the screen
I have tried like below
<div class="center">
<form asp-action="Index" method="get">
<div class="row">
<div class="col-lg-12">
<div class="row mb-3">
<div class="col-lg-4 col-md-2 form-check-inline mr-0">
<label class="col-auto" for="holiday"> Find by Holiday </label>
<input type="text" class="form-control" name="SearchString" value="#ViewData["CurrentFilter"]" />
</div>
<div class="col-lg-4 col-md-2 form-check-inline mr-0">
<input type="submit" value="Search" class="btn btn-info" />
<a class="btn btn-link" asp-action="Index">Back to Full List</a>
</div>
<div class="col-lg-4 col-md-2 form-check-inline mr-0" style="text-align:right">
<a class="btn btn-info" asp-action="Create">Create New</a>
</div>
</div>
</div>
</div>
</form>
</div>
And the UI shows up like below
Can anyone help say what is that I am missing why all the things appear so close, I tried adding the style="text-align:right" so the Create new will appear towards the right
***** EDIT *****
You could try this way to implement accordingly as per your
expectations like below:
Asp.net Submit Form With CSS
<div class="center">
<form asp-action="Index" method="get">
<div class="row">
<div class="col-md-12">
<div class="col-md-2">
<label class="col-auto" for="holiday" style="margin-top:10px;"> Find by Holiday </label>
</div>
<div class="col-md-3" style="margin-left: -50px;" >
<input type="text" class="form-control" name="SearchString" value="#ViewData["CurrentFilter"]" />
</div>
<div class="col-md-1">
<input type="submit" value="Search" class="btn btn-info" />
</div>
<div class="col-md-3">
<a class="btn btn-link" asp-action="Index">Back to Full List</a>
</div>
<div class="col-md-2">
<a class="btn btn-info" asp-action="Create">Create New</a>
</div>
<div class="col-md-1"></div>
</div>
</div>
</form>
</div>
Output
Note: You could set your CSS in different class file. I have shown you how could you achieve that using inline CSS snippet. You
could use separate file as well. But this is the right and convenient
way to do what you are trying to.
My first guess is caused by your class 'col-md-2'. You can change all of 'col-md-2' to 'col-md-4' to test.
try adding ml-auto on the 'Create New' button

Select radio button when clicked outside input

I'm using a standard Bootstrap 4 accordion with a radio button inside of it. Here is my code:
<div class="card">
<div class="card-header" id="headingOne">
<h2 class="mb-0">
<button class="btn btn-link btn-block text-left" type="button" data-toggle="collapse" data-target="#tm-stripe-div" aria-expanded="true" aria-controls="tm-stripe-div">
<div class="d-flex justify-content-between">
<div class="stripe-payment-div">
<input class="form-check-input" type="radio" name="paymentRadio" id="stripePayment" value="">
<label class="form-check-label" for="stripePayment"> Credit Card (Stripe) </label>
</div>
</div>
</button>
</h2>
</div>
</div
When i click outside the input field the radio button is not selected. I know the best way would be to use jquery, but is there a way to do it with css only?
I'd like the radio button selected when the use clicks anywhere inside the .card class.
Thanks
I'd recommend using JavaScript but if you really want to do it without, you can use the trick that a lot of custom form controls use.
Basically wrap it in a label and use the for attribute to point to your radio.
Had to also convert your button to an a because the clicks events weren't registering.
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div class="card">
<label for="stripePayment" class="mb-0">
<div class="card-header" id="headingOne">
<h2 class="mb-0">
<a class="btn btn-link btn-block text-left" data-toggle="collapse" data-target="#tm-stripe-div" aria-expanded="true" aria-controls="tm-stripe-div">
<div class="d-flex justify-content-between">
<div class="stripe-payment-div">
<input class="form-check-input" type="radio" name="paymentRadio" id="stripePayment" value="">
<span class="form-check-label" for="stripePayment"> Credit Card (Stripe) </span>
</div>
</div>
</a>
</h2>
</div>
</label>
</div>

Issues with Bootstrap Label and Input Field Alignment

I have the following form in my Angular app Using Bootstrap 4. I want my form label and input text box to be on the same line but its not working. The label and the input text box appears on separate lines. I have searched but couldn't find any better answer ::
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" />
<div class="col-md-12">
<form class="form-horizontal" [formGroup]="parentCategoryForm" autoComplete="off">
<div class="form-group">
<label class="control-label col-md-2" for="parent">Category name</label>
<div class="col-md-10">
<input type="text" formControlName="parentName" name="parentName" class="form-control" id="parentName" />
</div>
</div>
<div class="btn-toolbar pull-right">
<button type="button" (click)="cancel()" class="btn btn-outline-danger btn-sm mr-4">Cancel</button>
<button type="submit" class="btn btn-outline-primary btn-sm">Submit</button>
</div>
</form>
</div>
</div>
I am following the tutorials from this site Creating Horizontal Form Layout
What am I doing wrong?
please add class row on form-group
<div class="form-group row"> </div>
Use the input-group class. Follow This

Add clickable icon with input-group class to textbox

I have created a Textbox and a submit button with the help of input-group in Bootstrap:
<div class="form-group">
<div class="input-group input-group-lg col-lg-6 col-centered">
<input type="text" class="form-control">
<span class="input-group-btn">
<button type="button" class="btn btn-default">
Search
</button>
</span>
</div>
</div>
I want to add an icon for geolocation in the textbox which is clickable, I tried to do many things like adding another span with input-group-addon but that's creating a button kind of thing. I want the icon to be inside the textbox and make it clickable. Can anybody suggest a way to do it?
Add an anchor set it a class of glyphicon and then make its position:absolute like one below:
DEMO
<div class="input-group input-group-lg col-lg-6 col-centered">
<input type="text" class="form-control">
<span class="input-group-btn">
<button type="button" class="btn btn-default">
Search
</button>
</span>
</div>
CSS
.glyphicon-map-marker{
position:absolute;
z-index:1000;
top:30%;
left:2%;
}
a.glyphicon-map-marker
{
text-decoration: none !important;
}
Anirudh, Hi there, You could probably try something like this without all the extra css.
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<div class="form-group">
<div class="input-group input-group-lg col-lg-6 col-centered">
<a href="#" onclick="alert('clicked');" ></a>
<div class="input-group-addon glyphicon glyphicon-map-marker btn"></div>
<input type="text" class="form-control">
<span class="input-group-btn">
<button type="button" class="btn btn-default">
Search
</button>
</span>
</div>
</div>
<div class="row">
<div class="col-sm-2 col-md-2 col-lg-2"></div>
<form ng-submit="search(searchterm)">
<div class="form-group">
<div class="input-group input-group-lg col-sm-8 col-md-8 col-lg-8 col-centered">
<input type="text" class="form-control" ng-model="searchterm">
<span class="input-group-btn">
<button type="submit" class="btn btn-default">
<span class="glyphicon glyphicon-search"></span>
</button>
</span>
</div>
</div>
</form>
<div class="col-sm-2 col-md-2 col-lg-2"></div>
</div> <!-- end row -->
My client wanted a search box with a clickable search glyphicon on the right, and the search box centered in the window, the search box bigger than normal (input-group-lg), with responsive views. I was a miserable wretch until I saw AngularJR's answer. :-)
.input-group abbr{
font-size: 23px;
position: absolute;
right: 16%;
top: 6px;
z-index: 500;
}
<div class="form-group">
<div class="input-group input-group-lg col-lg-6 col-centered">
<input type="text" class="form-control">enter code here
<abbr><i class="fa fa-map-marker"></i></abbr>
<span class="input-group-btn">
<button type="button" class="btn btn-default">
Search
</button>
</span>
</div>
</div>

Make column stretch to fill whatever space it can in Bootstrap

I have this issue:
The html is as follows:
<div class="row">
<div ng-cloak class="col-md-7 col-sm-6 col-xs-12">
<form class="form">
<input type="text" class="form-control" />
</form>
</div>
<div class="col-md-5 col-sm-6 col-xs-12 no-wrap">
<span class="push-buttons-away-from-search-bar btn-group" role="group">
<a class="btn btn-lg" href="">A link</a>
<a class="btn btn-lg" href="">Another link</a>
</span>
</div>
</div>
Can you think of a responsive (bootstrap) way of making the search bartake up all space it can, and leave space for the 2 buttons on the side.
Notice the spacing between the 2 buttons, the button grouping styling was getting in the way... Perhaps you suggest using button groups?
What you're likely looking for, assuming you're using Bootstrap 3, is Justified Buttons. Red: http://getbootstrap.com/components/#btn-groups-justified
Example:
<div class="row">
<div class="col-sm-8">
<input type="text" class="form-control" />
</div>
<div class="col-sm-4">
<div class="btn-group btn-group-justified" role="group" aria-label="Justified button group">
Left
Right
</div>
</div>
</div>
JSFiddle: Note that this can be extended to more than one button.
Update
Since you need the input to scale without the buttons scaling, have you tried Segmented Buttons on an Input Group? Ref: http://getbootstrap.com/components/#input-groups-buttons-segmented
<div class="input-group">
<input type="text" class="form-control" aria-label="...">
<div class="input-group-btn">
<button type="button" class="btn btn-default">Button One</button>
<button type="button" class="btn btn-default">Button Two</button>
<button type="button" class="btn btn-default">Button Three</button>
</div>
</div>
JSFiddle: Note this won't give you a space between the buttons.