ALLOYUI Datepicker setter and getter method - datepicker

I have two input text box startdate and enddate
<input type="text" id="startdate"/>
<input type="text" id="enddate"/>
I need two simple things
On click of startdate and selection of start date, need to update
end date with +7 days.
Format needed is mm/dd/yyyy
So if any one click startdate with 01/01/2015 i.e 1st January 2015 , than end date should automatically set with 01/08/2015
On selection of startdate, I need to get enddate open automatically.
The datepicker Library I had used is ALLOYUI datepicker version 3.0
http://alloyui.com/examples/datepicker/
Can anyone please write down code please.
Guys
<script>
var datefrom;
YUI().use(
'aui-datepicker',
function(Y) {
datefrom = new Y.DatePicker(
{
trigger: '#dpfrom',
popover: {
zIndex: 1
},
calendar: {
//maximumDate : new Date(today.getFullYear(),today.getMonth()+1,today.getDate()),
minimumDate : new Date(),
},
on: {
selectionChange: function(event) {
}
}
}
);
}
);
//console.log(james);
</script>
I found the may to set minimum and maximum date but still i donot have the way to set end date +7 days to current date.

Please find similar and working one for me. Please customize it if you need anything.
<input class="form-control" type="text" id="selecteddate" placeholder="Day, Mon dd, yyyy"></input>
YUI().use(
'aui-datepicker',
function(Y) {
var datepicker = new Y.DatePicker(
{
trigger: 'input',
popover: {
zIndex: 1
},
after: {
selectionChange: function(event) {
event.preventDefault();
Y.log(datepicker.getSelectedDates());
var myDate=Y.DataType.Date.addDays(new Date(datepicker.getSelectedDates()),+6);
if (myDate.isValid()) {
$("#selecteddate").val(myDate);
}
}
}
}
);
}
);
Date.prototype.isValid = function () {
// An invalid date object returns NaN for getTime() and NaN is the only
// object not strictly equal to itself.
return this.getTime() === this.getTime();
};

Related

date-picker global definition for firstDayOfWeek from Element-Ui possible?

I'm using the component DatePicker from Element-Ui.
The firstDayOfWeek, which is shown in the calender is set to Sunday by default. I want to set it to Monday, like so:
<el-date-picker
type="date"
format="dd.MM.yyyy"
value-format="yyyy-MM-dd"
v-model="expireDate"
:picker-options="pickerOptions"
/>
In my data object I have:
data() {
return {
expireDate : ''
pickerOptions: {
firstDayOfWeek: 1
}
}
}
But I want to define the firstDayOfWeek globally, because I have many datePickers in my Code. Ist this possible?
I already tried this, but it's not working:
Vue.use(ElementUI);
const pickerOptions = {
firstDayOfWeek: 1
}
Vue.use(DatePicker, pickerOptions);

Date Picker is not disabling dates

I need to disable the first and third Wednesday in each month. The code I am using is below.This was working but when I added the new dates for 2021 it stopped working. Please help. Thanks
<script>
var dates = ["6-3-2019","20-3-2019","3-4-2019","17-4-2019","1-5-2019","15-5-2019","5-6-2019","19-6-2019","3-7-2019","17-7-2019","7-8-2019","21-8-2019","4-9-2019","18-9-2019","2-10-2019","16-10-2019","6-11-2019","20-11-2019","4-12-2019","18-12-2019","1-1-2020","15-1-2020","5-2-2020","19-2-2020","4-3-2020","18-3-2020","1-4-2020","15-4-2020","6-5-2020","20-5-2020","3-6-2020","17-6-2020","1-7-2020","15-7-2020","5-8-2020","19-8-2020","2-9-2020","16-9-2020","7-10-2020","21-10-2020","4-11-2020","18-11-2020","2-12-2020","16-12-2020","06-01-2021","20-01-2021","03-02-2021","17-02-2021","03-03-2021","17-03-2021","07-04-2021","21-04-2021","05-05-2021","19-05-2021","02-06-2021","16-06-2021","07-07-2021","21-07-2021","04-08-2021","18-08-2021","01-09-2021","15-09-2021","06-10-2021","20-10-2021","03-11-2021","17-11-2021","01-12-2021","15-12-2021"];
function DisableDates(date) {
var string = jQuery.datepicker.formatDate('dd/mm/yy', date);
return [dates.indexOf(string) == -1];
}
$(function() {
$("#datepicker2").datepicker({
beforeShowDay: DisableDates,
minDate: +1
});
});
</script>

Vue data model change not reflected in bound component

A jQuery datepicker is wrappped in a Vue component. The component emits an update message used to update the app model.
The app has two datepicker input fields:
startDate
adjustmentDate
When startDate is modified, adjustmentDate is to be updated to the next first or fifteenth of the month. However, the adjustmentDate datepicker component is not being notified of the update.
Expected behaviour:
startDate datepicker onSelect triggers the Vue component emit which is captured by Vue method updateStartDate
method updateStartDate sets model property adjustmentDate
It was hoped this would trigger the adjustmentDate component update since the adjustmentDate model attribute is bound to the datepicker componentDate property which has a watch.
But changing the model doesn't have the affect of notifying the component.
Any suggestions how to do this properly and show the newly calculated adjustmentDate when the startDate is changed?
Demo code:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<link rel="stylesheet" href="http://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://unpkg.com/vue"></script>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
</head>
<body>
<div id="app">
<div><label>Start date</label></div>
<div>
<date-picker
v-model="startDate"
v-bind:component-date="startDate"
date-format="yy-mm-dd"
#update-date="updateStartDate"
v-once
></date-picker>
</div>
<div><label>Adjustment date</label></div>
<div>
<date-picker
v-model="adjustmentDate"
v-bind:component-date="adjustmentDate"
date-format="yy-mm-dd"
#update-date="updateAdjustmentDate"
v-once
></date-picker>
</div>
</div>
<script>
Vue.component('date-picker', {
props: ['dateFormat', 'componentDate'],
template: '<input/>',
mounted: function() {
var self = this;
var _convertDateStringToDate = function(dateString) {
var dateParts = dateString.split("-");
var year = dateParts[0];
var month = dateParts[1];
var dayOfMonth = dateParts[2];
return new Date(year, month, dayOfMonth);
};
$(this.$el).datepicker({
dateFormat: this.dateFormat,
onSelect: function(date) {
self.$emit('update-date', _convertDateStringToDate(date));
},
onClose: function(date) {
self.$emit('update-date', _convertDateStringToDate(date));
}
});
$(this.$el).datepicker('setDate', this.componentDate);
},
watch: {
componentDate: function(newValue, oldValue) {
$(this.$el).datepicker('setDate', this.componentDate);
}
},
beforeDestroy: function() {
$(this.$el).datepicker('hide').datepicker('destroy');
}
});
var _calculateAdjustmentDate = function(date) {
var year = date.getFullYear();
var month = date.getMonth();
var dayOfMonth = date.getDate();
if (dayOfMonth > 15) {
month = month + 1;
dayOfMonth = 1;
} else if (dayOfMonth > 1 && dayOfMonth < 15) {
dayOfMonth = 15;
}
return new Date(year, month, dayOfMonth);
};
var data = function() {
var now = new Date();
return {
startDate: now,
adjustmentDate: _calculateAdjustmentDate(now),
};
};
new Vue({
el: '#app',
data: data,
methods: {
updateStartDate: function(date) {
this.startDate = date;
this.adjustmentDate = _calculateAdjustmentDate(date);
},
updateAdjustmentDate: function(date) {
this.adjustmentDate = date;
},
}
});
</script>
</body>
</html>
You need to remove the v-once directive from your adjustment date component as it prevents re-rendering when the data changes.
Additionally, you can simply put _calculateAdjustmentDate into a computed property, see Computed Properties.
See your updated example here: https://codepen.io/anon/pen/VQYarZ
There are some other issues with your code, I suggest you look into the Vue guide, especially at Method Event Handlers and Computed Properties as well as into Reactivity in Depth.
Also, _calculateAdjustmentDate does not really do what you describe, so you might look into this as well. You might consider Moment.js

How do I manage two datepickers if I want to set another datepicker according to date selected in first? Bootstrap datepicker

This is my code. I want to set a date according to date selected in first datepicker. How do I do this?
<input type="text" placeholder="From" class="week" id="dt1">
<input type="text" placeholder="To" class="week" id="dt2">
$(function() {
$("#dt1").datepicker({
minDate: "-",
maxViewMode: "weeks",
format: "dd-mm-yy",
clearBtn: true,
orientation: "bottom auto"
/*calendarWeeks: true,
todayHighlight: true*/
});
$("#dt2").datepicker({
minDate: 0,
format: 'dd-mm-yyyy',
endDate: "today"
})
});
Ok so with the option given you just must "listen" when the dates changed that's basically what the events provided does, so we're going to use changeDate on both #From and #To Picker to just allow select that week dates.
Note 1: I recommend you to disable the #To to avoid picker dates ahead, should be the same without it though.
Note 2: I removed the codes that you have commented out.
<input type="text" placeholder="From" class="week" id="dt1">
<input type="text" placeholder="To" disabled="disabled" class="week" id="dt2">
$(function() {
$("#dt1").datepicker({
minDate: "-",
maxViewMode: "weeks",
format: "dd-mm-yy",
clearBtn: true,
}).on('changeDate', function(event) {
$('#dt2').removeAttr('disabled'); //We enable our #To Picker
var newDate = new Date(event.date);
newDate.setDate(newDate.getDate() + 6); //We add 6 days to our selected date
$("#dt2").datepicker("setStartDate", event.date); //Set as start point that selected day
$("#dt2").datepicker("setEndDate", newDate); //Set the final "MaxDate
});
//We do the same for this one but backwards to avoid puttin "invalid" dates
$("#dt2").datepicker({
minDate: 0,
format: 'dd-mm-yyyy',
endDate: "today"
}).on('changeDate', function(event) {
var newDate = new Date(event.date);
newDate.setDate(newDate.getDate() - 6);
//You can alway remove this line to allow your user to select any start date
$("#dt1").datepicker("setStartDate", newDate);
//And here we set our max date on From picker so he doesn't again enter "invalid" dates
$("#dt1").datepicker("setEndDate", event.date);
});
});

Date from input field not being stored

I set up my Angular-Meteor application to allow users editing their date of birth. I am using bootstrap3-datepicker on the input field.
The input field in the form is defined like this:
<div class="form-group">
<label for="dateOfBirth" class="control-label">Date of Birth:</label>
<input type="date" id="dateOfBirth" class="form-control" ng-model="profileEdit.profile.dateOfBirth"/>
</div>
Picking and displaying the date works fine in the front-end, but the date is not stored when I save my form (all other data is). If a date exists before editing the record with the form, the date gets lost.
This is my controller:
class ProfileEdit {
constructor($stateParams, $scope, $reactive) {
'ngInject';
this.profile = Meteor.user().profile;
$('#dateOfBirth').datepicker({
format: "dd.mm.yyyy",
weekStart: 1,
startDate: "01.01.1940",
startView: 2
});
}
save() {
var profile = {
firstName: this.profile.firstName,
lastName: this.profile.lastName,
gender: this.profile.gender,
dateOfBirth: this.profile.dateOfBirth,
level: this.profile.level,
description: this.profile.description
}
Meteor.call('users.profile.update', profile, function(error, result) {
if(error){
console.log("error", error);
}
if(result) {
console.log('Changes saved!');
profile = {}
}
});
}
}
Logging profileEdit.profile.dateOfBirth to the console before saving the form data yields undefined.
It appears to me I am already losing the date between the form and my save() method. Why could this be?
I had the same issue with another datepicker, it appears that when a third party plugin updates the DOM, it does not update the modal that is attached to it. What I had to do was use the datepicker's events to catch the change and programatically update the field, IE:
$('.datepicker').datepicker()
.on('changeDate', function(e) {
// update your model here, e.date should have what you need
});
http://bootstrap-datepicker.readthedocs.io/en/latest/events.html