Extend datepicker to start with dropdown using bootstrap - html

I have a requirement to display Datepicker with Dropdown as a single control, I have tried many samples available on the internet but they do not work for me.
My base code is given below with style in which I have to merge them.
<fieldset>
<div class="form-group">
<label class="col-sm-2 control-label">Date</label>
<div class="col-sm-4">
<select name="Year" class="form-control" ng-model="Year" required>
<option>2016</option>
<option>2015</option>
<option>2014</option>
</select>
<div ng-messages="form.formValidate.select.$error" ng-if="form.formValidate.$submitted" class="text-danger"><span ng-message="required">This field is required</span></div>
<div class="ui-datepicker shadow-clear">
<p class="input-group">
<input type="text" name="date" required="" class="form-control" />
<span class="input-group-btn">
<button type="button" class="btn btn-default"><em class="ion-calendar"></em></button>
</span>
</p>
<div ng-messages="form.formValidate.date.$error" ng-if="form.formValidate.$submitted" class="text-danger"><span ng-message="required">This field is required</span></div>
</div>
</div>
</div>
</fieldset>
Any kind of help would be appreciated.
Thanks in advance!
Edit
Opps! I missed mentioning that both controls should be side by side as displayed in below image.
Edit2
http://www.bootply.com/Tftcr9VVrH

I wrapped the elements in a div with class="form-inline" and put each group of elements into a div with class="form-group". I forked your bootply here
<fieldset>
<div class="form-inline">
<div class="form-group">
<label for="Year">Date</label>
<select name="Year" class="form-control" required="" ng-model="Year">
<option>2016</option>
<option>2015</option>
<option>2014</option>
</select>
<div class="text-danger" ng-if="form.formValidate.$submitted" ng-messages="form.formValidate.select.$error"><span ng-message="required">This field is required</span></div>
</div>
<div class="form-group">
<div class="ui-datepicker shadow-clear">
<div class="input-group">
<input name="date" class="form-control" required="" type="text">
<span class="input-group-btn">
<button class="btn btn-default" type="button"><em class="glyphicon glyphicon-calendar"></em></button>
</span>
</div>
<div class="text-danger" ng-if="form.formValidate.$submitted" ng-messages="form.formValidate.date.$error"><span ng-message="required">This field is required</span></div>
</div>
</div>

Related

Alignment of label and textbox

I am facing this issue again with the alignment which I am unable to rectify. I don't know what I am missing out. Please find the plunkr [https://plnkr.co/edit/UD0YZQhgOjIoJ1nqg7sb?p=preview] .Please maximise the plunkr output for the actual output I am getting. Any help people?
Html code:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<div ng-controller="headerCtrl">
<div class="container" style="padding-top:20px;">
<div ng-app="TimeSheet" data-ng-controller="headerCtrl" class="container" style="margin-top:60px">
<div ng-show="error" class="alert alert-danger alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">×</span><span class="sr-only">Close</span>
</button>
<p>{{ error }}</p>
</div>
<!--<p><a data-ng-click="showadd()" href="javascript:;" class="btn btn-primary">Generate Report</a></p>-->
<div class="panel panel-default">
<div class="panel-body">
<section>
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="form-horizontal">
<div class="form-group">
<label for="title" class="col-sm-5 control-label">UserID</label>
<div class="col-sm-4">
<select data-ng-model="user.userid" class="form-control" id="title" required>
<option value="" selected="selected">(Select User ID)</option>
<option value="user1">user1</option>
<option value="user2">user2</option>
<option value="user3">user3</option>
<option value="user4">user4</option>
</select>
<!--<input type="text" data-ng-model="user.userid" class="form-control" id="title" placeholder="Enter your User ID" required title="Enter your UserID" />-->
</div>
</div>
<div class="form-group">
<label for="title" class="col-sm-5 control-label">Status</label>
<div class="col-sm-4">
Active
<input name="Status" type="radio" data-ng-model="user.ResultStatus" value="Active" required title="Choose status"> In-Active
<input name="Status" type="radio" data-ng-model="user.ResultStatus" value="InActive" required title="Choose status">
</div>
</div>
<div class="form-group">
<label for="startDate" class="col-sm-5 control-label">Date</label>
<div class="col-sm-4">
<input name="startDate" data-ng-model="user.date" id="startDate" class="date-picker" required />
<!--<input type="text" data-ng-model="user.projectid" class="form-control" id="title" placeholder="Enter your Project ID" required title="Enter your ProjectID" />-->
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-4 col-sm-4">
<span data-ng-hide="editMode">
<input type="submit" value="Generate" ng-disabled="adduserform.$invalid" data-ng-click="add()" class="btn btn-primary" />
</span>
<span data-ng-show="editMode">
<input type="submit" value="Update" ng-disabled="adduserform.$invalid" data-ng-click="update()" class="btn btn-primary" />
</span>
<input type="button" value="Cancel" data-ng-click="cancel()" class="btn btn-primary" />
</div>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
</div>
you can see the alignment issue here in this image below
To make the date input span the whole width, you need the .form-control class on it.
<input name="startDate" data-ng-model="user.date" id="startDate" class="form-control date-picker" required />
Also note that the <input> tag must have a type attribute with it.
You have a container within a container for your timesheet div. Removing the .container class from the timesheet div fixes the alignment issue.
Also, put the <table> in a row and a column:
<div class="row">
<div class="col-md-12">
<!-- Your table here -->
<table class="table table-hover">
...
</table>
</div>
</div>
See it working here.

How to perform validations in angular2

I am trying to perform validations to my fileds in such a way that when i click on submit button it must show error to fields which are empty.Can anyone please help me .............
<div *ngFor="let detail of details" class="nopadding col-sm-12">
<form [formGroup]="form" (ngSubmit)="onSubmit(form.value)" class="nobottommargin col-sm-12 formpaddingcss" name="template-contactform" novalidate="novalidate">
<div class="form-process"></div>
<div class="col_half">
<label for="template-contactform-name">First Name <small>*</small></label>
<div class="input-group divcenter">
<span class="input-group-addon noradius"><i class="icon-user iconcolorcss"></i></span>
<input type="email" data-toggle="tooltip" data-placement="top" title="Enter Firstname!" name="widget-subscribe-form-email" class="form-control required email formcontrolheight" [formControl]="form.controls['firstname']" [(ngModel)]="detail.firstname" placeholder="First Name" aria-required="true">
</div>
</div>
<div class="clear"></div>
<div class="col_full">
<button class="button button-blue button-mini bottommargin-sm pull-right text-right" type="submit">Save</button>
</div>
<div class="clear"></div>
</div>
Try this for simple validations....
<input type="email" title="Enter Firstname!" class="form-control required email formcontrolheight" [(ngModel)]="detail.firstname" placeholder="First Name" aria-required="true">
<span *ngIf="clicked && !detail.firstname || !detail.firstname.trim()" class="error">Error Its empty</span>
<button (click)="clicked = true"></button>
I don't its correct or not but this works fine with me. Refer this code:
<form id="discussion_form" name="discussion_form" ng-submit="addDiscussion(discussion_form.$valid)" novalidate>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label for="dis_title">Topic<span>*</span></label>
<input type="text" id="dis_title" class="form-control" name="dis_title" placeholder="e.g., about independence day celebration." required ng-model="discussionDetails.dis_title">
<label for="dis_title" class="form_errors" ng-show="discussion_form.dis_title.$invalid && !discussion_form.dis_title.$pristine">Please enter a discussion topic</label><!--To show error msg-->
</div>
</div>
</div>
<button type="submit" class="btn btn-primary pull-right" ng-disabled="discussion_form.$invalid">Submit</button>

Bootstrap inline form with labels above input

I want to create an inline form using bootstrap with labels above input text fields but the result looks so messed up.
This is what i tried:
<form id="form" method="post" class="form-inline" >
<div class="row">
<div class="col-md-2">
<label for="from">from:</label>
<input type="text" class="form-control form-text" />
</div>
<div class="col-md-2">
<label for="to">to:</label>
<input type="text" class="form-control form-text"/>
</div>
<div class="input-group date col-md-2" id="datepicker">
<label for="checkin">check in</label>
<input type="text" class="form-control datepicker" name="processdate" />
<span class="input-group-addon btn"><i class="glyphicon glyphicon-calendar"></i> </span>
</div>
<div class="input-group date col-md-2" id="datepicker">
<label for="checkout">check out</label>
<input type="text" class="form-control datepicker" name="processdate" />
<span class="input-group-addon btn"><i class="glyphicon glyphicon-calendar"></i> </span>
</div>
<div class="col-md-2">
<input type="submit" class="btn btn-default" value="submit"/>
</div>
</div>
</form>
this is what i got:
result
how do i get the submit button to right position and the glyphicons heights the same as the input fields what am i doing wrong?
I made some edits to your html : https://jsfiddle.net/05t4s041/
<form id="form" method="post" class="form-inline" >
<div class="row">
<div class="col-md-2">
<label for="from">from:</label>
<input type="text" class="form-control form-text" />
</div>
<div class="col-md-2">
<label for="to">to:</label>
<input type="text" class="form-control form-text"/>
</div>
<div class="col-md-2">
<label for="checkin">check in</label>
<div class="input-group date" id="datepicker">
<input type="text" class="form-control datepicker" name="processdate" />
<span class="input-group-addon btn"><i class="glyphicon glyphicon-calendar"></i> </span>
</div>
</div>
<div class="col-md-2">
<label for="checkout">check out</label>
<div class="input-group date" id="datepicker">
<input type="text" class="form-control datepicker" name="processdate" />
<span class="input-group-addon btn"><i class="glyphicon glyphicon-calendar"></i> </span>
</div>
</div>
<div class="col-md-2">
<input type="submit" class="btn btn-default" value="submit"/>
</div>
</div>
</form>
you could put divs with bootstrap classes around your label and control like:
<div class="col-md-2">
<div class="row">
<div class="col-md-6">
<label for="from">from:</label>
</div>
<div class ="col-md-6">
<input type="text" class="form-control form-text" />
</div>
</div>
</div>
The row div may be sufficient: it put's elements in a row put I like to put extra bootstrap classes around my controls so I can modify them. For example that the label has a smaller width than the control itself.

Fieldsets Using Bootstrap Grids

I have the following markup using bootstrap grids:
<form id="store-form" class="user-form">
<div class="row">
<div class="col-sm-6">
<fieldset id="store-form-store-fields">
<label>Store Nickname</label>
<input id="store-nickname-field" type="text" name="nickname" required class="form-control">
</fieldset>
</div>
<fieldset id="store-form-location-fields">
<div class="col-sm-6">
<label>Store Address</label>
<input id="store-street-field" type="text" name="street" required class="form-control">
</div>
<div class="col-sm-6">
<label>City</label>
<input id="store-city-field" type="text" name="city" required class="form-control">
</div>
<div class="col-sm-3">
<label>State</label>
<select id="store-state-field" name="state_id" required class="form-control">
<option>- Select a State -</option>
<option value="MA">Massachusetts</option>
<option value="CA">California</option>
</select>
</div>
<div class="col-sm-3">
<label>Zip Code</label>
<input id="store-zipcode-field" type="text" name="zipcode" required class="form-control">
</div>
</fieldset>
</div>
<div class="submit-wrapper">
<button id="store-form-submit" type="submit" class="btn btn-primary submit-button">Save</button>
</div>
</form>
As you can see, I'm trying to use fieldsets to group the fields into two groups. I need to do this so that I can create Backbone.js view for each group of fields separately. Obviously this breaks the grid, since I have an immediate child of .row that isn't a column div.
Is there any way at all to make fieldsets work with a form that is layed out using Bootstrap grids?
Edit for clarification: My goal is for the layout to behave the same as if the fieldsets were removed from the example.
What about wrapping the second <fieldset> in a div.col-md-6 and putting all the contents of the second <fieldset> in div.row? That way you are not skipping the css column definition. Let me know if that helps.
UPDATE:
I modified the code to use responsive resets and col-md-pull/col-sm-pull. Seems to remain responsive. This may be closest solution possible as you would not be able to properly close the col definition <div> within that fieldset to get proper clearing.
http://jsfiddle.net/s9baun7c/4/
<form id="store-form" class="user-form">
<div class="row">
<div class="col-sm-6">
<fieldset id="store-form-store-fields">
<label>Store Nickname</label>
<input id="store-nickname-field" type="text" name="nickname" required class="form-control" />
</fieldset>
</div>
<fieldset id="store-form-location-fields">
<div class="col-sm-12">
<label>Store Address</label>
<input id="store-street-field" type="text" name="street" required class="form-control" />
</div>
<div class="clearfix visible-md-block"></div>
<div class="clearfix visible-sm-block"></div>
<div class="row">
<div class="col-md-12">
<div class="col-sm-12 col-sm-pull-12 col-sm-pull-12">
<label>City</label>
<input id="store-city-field" type="text" name="city" required class="form-control" />
</div>
<div class="clearfix visible-md-block"></div>
<div class="clearfix visible-sm-block"></div>
<div class="col-sm-6 col-sm-pull-12 col-sm-pull-12">
<label>State</label>
<select id="store-state-field" name="state_id" required class="form-control">
<option>- Select a State -</option>
<option value="MA">Massachusetts</option>
<option value="CA">California</option>
</select>
</div>
<div class="col-sm-6 col-sm-pull-12 col-sm-pull-12">
<label>Zip Code</label>
<input id="store-zipcode-field" type="text" name="zipcode" required class="form-control" />
</div>
</div>
</div>
</fieldset>
</div>
<br>
<div class="submit-wrapper">
<button id="store-form-submit" type="submit" class="btn btn-primary submit-button">Save</button>
</div>
</form>

BootStrap 3 Alignment of controls

I want to align TextBox which will be used as Searchbox and button.
Problem is when I use inline form class on div the textbox is loosing its width.
<div class="col-lg-6">
<input type="text" id="test" name="city" class="form-control input-lg" placeholder="E.g. Manchester">
<div class="form-inline">
<div class="form-group ">
<input type="text" id="city" name="city" class="form-control input-lg" placeholder="E.g. Manchester">
<input type="button" value="Search" class="form-control btn-lg"/>
</div>
</div>
</div>
what I'm missing here..
here is a good solution for you:
Screenshot:
Code:
<div class="form-group">
<input type="email" class="form-control" id="exampleInputEmail1" placeholder="E.g. Manchester" />
</div>
<div class="input-group">
<input type="text" class="form-control" placeholder="E.g. Manchester" />
<span class="input-group-btn">
<button class="btn btn-default" type="button">Search</button>
</span>
</div>
Result:
http://jsfiddle.net/j9EdZ/
You might be best using the col-md-* values here, e.g.:
<div class='col-lg-6'>
<form class='form'>
<div class='row'>
<div class='form-group'>
<div class='col-md-10'>
<input class='form-control input-lg' type='text' placeholder='E.g. Manchester'>
</div>
<div class='col-md-2'>
<input type='button' class='form-control btn btn-block' value='Search'>
</div>
</div>
</div>
</form>
</div>
Text-box is not loosing its width you can check here.
CODE : http://jsfiddle.net/Jaysinh/awYm3/
As per the Bootstrap documentation of Form you have to set the width of the element. Default is 100 % wide.
Requires custom widths
Inputs, selects, and textareas are 100% wide by default in Bootstrap. To use the inline form, you'll have to set a width on the form controls used within.
Here, check this out.
Demo
HTML
<div class="col-lg-6">
<form class="form-horizontal" role="form">
<div class="form-group">
<input type="text" id="test" name="city" class="form-control input-lg" placeholder="E.g. Manchester" />
</div>
<div class="form-inline">
<div class="form-group ">
<input type="text" id="city" name="city" class="form-control input-lg" placeholder="E.g. Manchester" />
<input type="button" value="Search" class=" btn btn-lg btn-default" />
</div>
<div class="form-group "></div>
</div>
</form>
</div>