Kendo Date to Date Time - html

I am switching between a Kendo Date-Time picker and a Kendo Date Picker. The Picker alternates between the two depending on if the user has selected "All Day" - which then only the Date Picker is shown.
However, when switching from the Date-Picker, to the Date-Time picker, if one alters the date then tries to switch, Kendo doesn't store the date, and shows the Date-Time picker as empty.
<div class="col-sm-6">
<label class=" control-label" for="start-date">Start Date & Time</label>
<input kendo-date-time-picker id="start-date-time" name="start-date-time"
data-ng-model="registeringUser.StartDate"
data-ng-required="true"
min="today"
max="howFarOut"
data-ng-show="!setAllDay">
<input kendo-date-picker id="start-date" name="start-date"
data-ng-model="registeringUser.StartDate"
data-ng-required="true"
min="today"
max="howFarOut"
data-ng-show="setAllDay">
<span class="help-block"></span>
</div>
<div class="col-sm-6">
<label class=" control-label" for="end-date">End Date & Time</label>
<input kendo-date-time-picker id="end-date-time" name="end-date-time"
data-ng-model="registeringUser.EndDate"
data-ng-required="true"
min="today"
max="howFarOut"
data-ng-show="!setAllDay">
<input kendo-date-picker id="end-date" name="end-date"
data-ng-model="registeringUser.EndDate"
data-ng-required="true"
min="today"
max="howFarOut"
data-ng-show="setAllDay">
<span class="help-block"></span>
</div>
I currently switch between the option by changing the visibility, and it works as long as one does not alter the Date-Picker and then switches back to Date-Time. Does anyone know how to store the date when switching back to Date-Time?
For example: If it was 2/02/20002 3:00 PM, then when switched to Date only, it becomes 2/02/2002. But if I change the date to 2/03/2002, then switch it back to Date-Time, the calendar then reads as empty- while I'd like it to read as 2/03/2002 12:00 AM
scope.setAllDay = false;
scope.cbSelected = function () {
if (scope.myCheckbox) { // when checked
scope.setAllDay = true;
} else {
scope.setAllDay = false;
}
};

You need to specify kendo date time picker parse-format and match it with kendo date picker format by default its follow your culture setting, e.g M/d/yyyy for en-US
<input kendo-date-time-picker
ng-model="dateString"
k-ng-model="dateObject"
k-parse-formats="['dd/MM/yyyy']"
ng-show="!allDay"/>
<input kendo-date-picker id="start-date" name="start-date"
k-format="dd/MM/yyyy"
ng-model="dateString"
ng-show="allDay">
See my dojo

Related

how to display date in HTML Date control using angular 13

While performing the edit operation using angular 13, I'm using HTML input type date. When fetching a date from the database, it is not showing the date in the textbox. Kindly help me.
update-movie.component.html
<div class="mb-2">
<label>Release Date</label>
<input type="date" name="releaseDate" class="form-control" [(ngModel)]="movieService.movieData.releaseDate"
#releaseDate="ngModel" [value]=movieService.movieData.releaseDate required
[class.is-invalid]="releaseDate.invalid && releaseDate.touched">
</div>```
I found the answer, instead of [value] I used [ngModel] and applied date pipe.
<label>Release Date</label>
<input type="date" name="releaseDate" class="form-control" [(ngModel)]="movieService.movieData.releaseDate"
#releaseDate="ngModel" [ngModel]="movieService.movieData.releaseDate | date : 'yyyy-MM-dd'" required
[class.is-invalid]="releaseDate.invalid && releaseDate.touched">
</div>

Can I change the current year of bsDatepicker?

In my typescript code I am just importing the => { BsDatepickerModule } from 'ngx-bootstrap/datepicker';
I have this html codel:
<div class="col-xs-12 col-12 col-md-4 form-group">
<input type="text"
placeholder="Datepicker"
class="form-control"
bsDatepicker>
</div>
The result is:
what I have.png
I want the basic calendar to begging form 2004.
Something like: what I want.png
How can I change the first year that pops-out to be 2004 instead of 2020?
If there is no value set for the datepicker it will default to the current date. This is what you see happening in your example.
What you can do is inside the html template add the [bsValue]="dateForDatepicker" attribute to your bsDatepicker input element.
<input type="text"
placeholder="Datepicker"
class="form-control"
bsDatepicker
[bsValue]="dateForDatepicker"
>
In the component you can then add dateForDatepicker = new Date("01-01-2014") which should cause the datepicker to display that value initially.
For more information you can check the documentation: https://valor-software.com/ngx-bootstrap/#/datepicker#date-initial-state

Compare date in date picker with current date

<div class="input-group" ng-init="d.expiredAt = toDate(d.expiredAt);">
<input type="text" class="form-control" uib-datepicker-popup="dd/MMM/yyyy"
is-open="popup1.opened" ng-required="false"
close-text="Close" ng-model="d.expiredAt" ng-readonly="!editing"/>
I want to compare this date with current date and highlight this field with red if it is < than current date.
I guess that the purpose of your feature is to notify / prevent user from selecting a date before today ?
If it's the case, the bootstrap-ui component you're using provides the feature :
minDate (Default: null) - Defines the minimum available date.
Requires a Javascript Date object.
If you declare the today's date in your controller :
$scope.now = new Date();
You can use it like this in your HTML :
<input type="text" min-date="now" class="form-control" uib-datepicker-popup="dd/MMM/yyyy"
is-open="popup1.opened" ng-required="false"
close-text="Close" ng-model="d.expiredAt" ng-readonly="!editing"/>
It will disable the selection of passed dates.

input field edit not updating ng-model for date picker?

I have created a date picker in Angular
<div class="datepicker-wrapper">
<label for="license_expiry_date">Start Date (YYYY-MM-DD)</label>
<input type="text" class="form-control" [ngModel]="fromDate | date: 'yyyy-MM-dd'" placeholder="Enter start date" (focus)="onPurchaseDateFocus('from')" name="start_date">
<div [hidden]="!isFromDatepickerVisible" class="datepicker-container">
<datepicker [(ngModel)]="fromDate" name="fromdatepicker" (selectionDone)="onDateSelectionDone('from')">
</datepicker>
</div>
</div>
I can select a date by using date picker which will update the ng-model, the input tag above the date picker is editable. but when I edit the date from the input field instead of date picker instead of selecting by date picker, ng-model is not getting updated.
Why is the value not updated when I edit the input field?
Not sure what's going wrong but my first guess is the one-way data binding on the form control.
[ngModel]="fromDate | date: 'yyyy-MM-dd'"
try to change it to
[(ngModel)]="fromDate | date: 'yyyy-MM-dd'"
More on two-way data binding
https://angular.io/docs/ts/latest/guide/template-syntax.html#!#two-way

How to disable or hide "Today" button for angularui-datepicker based on condition if its weekend

How to hide/disable "Today" button based on condition. Let's say if today is weekend. I want to hide "Today" button.
<div class="form-group">
<div class="input-group datePicker">
<input id="dt-date" name="dt-date" class="form-control"
type="text" size="10" ng-model-options="{updateOn: 'default'}"
required required-err-message="Date is Required"
uib-datepicker-popup="{{TestVm.datePickerFormat}}"
ng-model="TestVm.date"
is-open="TestVm.dateDatePicker.isOpen"
datepicker-options="TestVm.datePickerOptions"
close-text="Close" alt-input-formats="TestVm.datePickerAltInputFormats" />
<span class="input-group-btn">
<button type="button" ng-model-options="{updateOn: 'default'}" class="btn btn-default" ng-click="TestVm.dateDatePicker()">
<i class="glyphicon glyphicon-calendar"></i>
</button>
</span>
</div>
</div>
Datepicker options in Angular Controller
TestVm.datePickerOptions = {
formatYear: 'yy',
startingDay: 1,
showWeeks: false,
dateDisabled: myDisabledDates
};
Function which disables weekends
function myDisabledDates(dateAndMode) {
return (dateAndMode.mode === 'day' && (dateAndMode.date.getDay() === 0 || dateAndMode.date.getDay() === 6)) ;
}
Datepicker Image
The dateDisabled is used to disable the dates in the calendar so you cannot click on them, not to hide the Today button. If you wish to hide the Today button you are going to have to override the template used to display the calendar and give the Today button an ID so that you can reference it and hide it.
From the uid-datepicker documentation
template-url (Default: uib/template/datepicker/datepicker.html) - Add
the ability to override the template used on the component.
You should copy that template and give it your own name and then reference that. In the template, give the Today button an ID, e.g. ID="myTodayButton".
You will then need to write a function that gets the current day and if it is a weekend then disable or hide the myTodayButton.