Jquery datepicker - year then month then day - javascript

I am trying to use datepicker by http://foundation-datepicker.peterbeno.com/example.html to get the user to select a date.
The datepicker has a really nice year-picker and month-picker format instead of using the arrows, it has a nice selector.
year-picker
the only way to access the year picker I can tell is to click on the year at the top, however I want this to show first on default. once the user selects the year, then allow them to select the month using the month-picker
[month-picker][2] - 2: i.stack.imgur.com/CiIgU.png (i am unable to post more than 2 links currently as I am new to stackoverflow but here is the intended screenshot - same as below...)
I want them to first select the year, then the month, then day. However all the examples I see I don't see how to set all three beginning with year.
then finally the default day picker
[day-picker][3] - 3: i.stack.imgur.com/p3re2.png
Alternatively if the above is not possible could allow the user to select 3 separate times with 3 different datepickers - one for year, month, and day. I can get the month-picker only working with the following (but not the year picker):
<div class="row collapse date" id="dpMonths" data-date-format="mm/yyyy" data-start-view="year" data-min-view="year" style="max-width:200px;">
<div class="small-2 columns">
<span class="prefix"><i class="fa fa-calendar"></i></span>
</div>
<div class="small-10 columns">
<input size="16" type="text" value="02/2012" readonly>
</div>
<script>
$(function(){
$('#dpMonths').fdatepicker();
});
</script>
Is this possible?
There is tons of examples on this page, but if i try modify any of them it either breaks or doesnt do what I need it to do...
Kind regards,
Dave

The examples on the website above are not correct. I have managed to find the answer in one of the commits after much searching. Hopefully this answer may assist someone else.
$('.monthpicker').fdatepicker({
format : 'mm/yyyy',
startView : 1,
minView : 1
});
The views are numbered go up so 4 = year etc.
To select date going through year -> month -> day:
$('.monthpicker').fdatepicker({
format : 'mm/yyyy',
startView : 4,
minView : 2
});

Related

Limit time in v-calendar datepicker

I am working on a project where user request for appointment. I am using v-calendar which uses the datepicker.
I am facing a issue where user can request for appointment any time/ 24 hours which I need to set only for 9am - 5pm. I can see that we can limit date in date picker by using something like :max-date="value" but could not found how to limit the time.
Here is the working fiddle
some code from the project
name="appointment-date"
v-model="appointment_date"
mode="dateTime"
:is24hr="false"
:min-date="currentDate"
:model-config="dateTimePickerConfig"
:popover="{
visibility: 'click',
placement: 'auto',
}"
:masks="{ inputDateTime: 'MM/DD/YYYY h:mmA'}">
<template v-slot="{ inputValue, inputEvents }">
<div class="form-icon ">
<input-component
:value="inputValue"
v-on="inputEvents"
placeholder="MM-DD-YYYY h:mmA"
/>
<Icon name="date-time"/>
</div>
</template>
</date-picker>
Your help to solve the problem will be higly appreciated.
Thank you.
If I understood you well, you want to restrict picking specific hours. This is possible with v-calendar with the following property:
<v-date-picker v-model="date" :valid-hours="[0,3,4,5,8,16,20]" is24hr />
Please note the :valid-hours attribute. You can provide which hours should be available for the user to pick. If you want to allow them to pick minutes in specific 'intervals' you can use following as well:
<v-date-picker v-model="date" mode="dateTime" :minute-increment="15" />
Note :minute-increment property. This will allow user to pick between '15 minutes. So available numbers will be 00, 15, 30, 45. You can play with it.
Unfortunately, there is no way to disable minutes, which makes me sad. As if someone books appointment at 9:15 AM you would rather want to 'disable' 9:15 AM for next users. You could disable whole hour (9 AM) but not specifically 9:15, so that 9:00, 9:30 and 9:45 would still be available. At least I don't know any easy way.
Hope this helps anyone.
================ UPDATE =================
Note that v-calendar added those additional properties in specific v-calendar version. I've been using it with v2.4., seems like v2.3. does not have it yet.

Format input values to hour and minute format (hh:mm)

I have one input field for time entry , need to enter hour and minute (HH:mm Format) .So how can input values automatically formatting . Eg: input values automatically formatting with HH:mm format (11:30).Any help would be appreciated.
You can use uib-timepicker directive for this purpose.It is easy to use and lot more customizable like you can switch between 12/24H etc. The doc explains it pretty clearly.
<div uib-timepicker ng-model="mytime" ng-change="changed()"
hour-step="hstep" minute-step="mstep" show-meridian="ismeridian">
</div>
you just write{{"HH:mm"}} in $scope
value = {{a.value | date: "HH:mm"}}

Angular-Bootstrap Datepicker - Keep Today's date highlighted when another date is selected

Note: I checked it in SO and could not find any Question/Response that help related to this issue. Please guide me if it already exists.
I am using Angular Bootstrap's ui-datepicker library.
I am currently embedding the calender on the page. I am using angular.js, Bootstrap.css
Highlight today's date by default
Select another date will highlight the selected date. But, losing the highlight for the today's date.
Disable the previous dates in the respective month.
Here is the sample code:
<div ng-controller="DatepickerDemoCtrl">
<pre>Selected date is: <em>{{dt | date:'fullDate' }}</em></pre>
<div style="display:inline-block; min-height:290px;">
<datepicker ng-model="dt" min-date="minDate" show-weeks="true" class="well well-sm" custom-class="getDayClass(date, mode)"></datepicker>
</div>
</div>
Here is the Link to Plunkr
Any suggestions (regarding highlight today date when i select another date) will be appreciated.
You can use custom-class(date, mode) attribute. You actually already use it in your plunker. In this attribute you can include an expression that will return a custom class based on passing date and mode.
In your case you correctly define this attribute in datepicker element:
<datepicker ng-model="dt" min-date="minDate"
show-weeks="true" class="well well-sm"
custom-class="getDayClass(date, mode)"></datepicker>
You just have to change getDayClass function and make it do what you want to do: return a css class that highlights current date's button no matter what date is selected in datepicker.
$scope.getDayClass = function(date, mode) {
if (mode === 'day') {
var dayToCheck = new Date(date).setHours(0,0,0,0);
var currentDay = new Date().setHours(0,0,0,0);
if (dayToCheck === currentDay) {
return 'highlight-current-date';
}
}
return '';
};
Of course, add highlight-current-date class to you css file.
.highlight-current-date button {
background: aqua;
}
Check updated plunker here.

Bootstrap datepicker format not working on initialization

I am trying to use angular-bootstrap datepicker module in my app and encountered small problem. I use input text and button for displaying date like this:
<div class="row" id="datePicker">
<p class="input-group">
<input type="text" class="form-control" datepicker-popup="{{format}}" ng-model="currentDate"
is-open="opened" datepicker-options="dateOptions" date-disabled="disableDt(date, mode)"
ng-required="true" close-text="Close" show-button-bar="false" ng-init="" readonly/>
<span class="input-group-btn">
<button type="button" class="btn btn-default" ng-click="open($event)">
<i class="glyphicon glyphicon-calendar"></i>
</button>
</span>
</p>
</div>
And due to using angular google maps I have to manually bootstrap my app. It seems that due to manual bootstrapping, datepicker is unable to properly format the date and displays whole unformatted date. As I choose any date from datepicker, date is then displayed correctly in the input field. What is more, model changes don't force format to change (e.g. initially I got some dates from json file and they were displayed in the field, but without formatting too).
Example below:
Initial date: Fri Jan 17 2014 01:00:00 GMT+0100 (CET)
Expected date (and one displayed after choosing the same day): 17 January 2014
Is there any way of refreshing this widget so it knows proper formatting at the beginning or changing it at the proper moment to initialize properly?
EDIT: As I moved datepicker to fragment, it should not have problems with not initialized model (this fragment is loaded later). Still, problem occur - date is not formatted and seems not to be connected with formatter or model at all (e.g. making format dropdown and choosing different values as in tutorial doesn't work until date is chosen inside datepicker).
EDIT 2 Solution from the link provided by camden_kid worked! :) Details in his comment.
Answer could be found here:
AngularJS 1.3 - Datepicker initial format is incorrect
I manually formatted the date on initialization as below:
$scope.currentDate = $filter('date')(new Date(), $scope.format);
However, better solution would be to overload directive as follows (taken from the original link):
angular.module('myApp').directive('datepickerPopup', function (dateFilter, datepickerPopupConfig) {
return {
restrict: 'A',
priority: 1,
require: 'ngModel',
link: function(scope, element, attr, ngModel) {
var dateFormat = attr.datepickerPopup || datepickerPopupConfig.datepickerPopup;
ngModel.$formatters.push(function (value) {
return dateFilter(value, dateFormat);
});
}
};
});
When date was changed by datepicker afterwards, datepicker itself handled any date formatting :)
Thanks to #camden_kid for providing the link! :)

AngularStrap data-start-date not allowing date selection

I've got this angular datepicker
<input type="text" bs-datepicker data-start-date="01/10/13" data-end-date="29/04/14" placeholder="Earliest date" id="BoundaryFrom" name="BoundaryFrom" ng-model="chartData.boundary.min" data-date-format="d M yyyy" />
(At the moment I've put in hard coded start and end dates just to test the functionality out. Later I will put in an Angular expression)
Now, this part data-start-date="01/10/13" data-end-date="29/04/14" correctly only displays the dates between 1st October 2013 and 29 April 2014 in the calendar control but the problem is none of those dates is selectable. I can still type in the textbox though. Why are they not selectable?
It seems that the the start date and the end date should be more specific, as well as the options being data-min-date and data-max-date. Your start and end date code should be data-min-date="10/01/2013" data-max-date="04/29/2014". The full line will be
<input type="text" bs-datepicker data-min-date="10/01/2013" data-max-date="04/29/2014" placeholder="Earliest date" id="BoundaryFrom" name="BoundaryFrom" ng-model="chartData.boundary.min" data-date-format="d M yyyy" />
Also, I think the format of the date for that would be "mm/dd/yyyy" instead of "dd/mm/yyyy" like you originally did.
Here is a plunker of working code. The calendar only allows selected dates between 1st October 2013 and 29 April 2014. I hope this helps!!!
edit: fixed a typo. Also, an upvote or accepted answer would be awesome :)

Categories

Resources