Can someone tell me how to display holidays using antd-datepicker by getting holiday information from a server.
Before I call the dateRender callback, I want to get the startdate and the enddate of the holiday information.
Try this picking from the example:
<DatePicker
dateRender={(current) => {
const style = {};
if (InHolidayDates(current.date())) {
style.border = '1px solid #1890ff';
style.borderRadius = '50%';
}
return (
<div className="ant-calendar-date" style={style}>
{current.date()}
</div>
);
}}/>
Write a InHolidayDates(date) function which checks if the "date" is in the Holidays Date list. If it exists it returns true. Else false.
Let me know if you need help with the fetching and comparison of dates.
Related
As the title suggests I am using DateRangePicker to add date ranges to an array. If possible I would like to be able to "grey" out already selected dates in the array. Is there anyway to do this?
Here is the solution to returning the dates in-between the range in case anyone else needs it.
List<DateTime> getDaysInBetweenIncludingStartEndDate(
{required DateTime startDateTime, required DateTime endDateTime}) {
// Converting dates provided to UTC
// So that all things like DST don't affect subtraction and addition on dates
DateTime startDateInUTC =
DateTime.utc(startDateTime.year, startDateTime.month, startDateTime.day);
DateTime endDateInUTC =
DateTime.utc(endDateTime.year, endDateTime.month, endDateTime.day);
// Created a list to hold all dates
List<DateTime> daysInFormat = [];
// Starting a loop with the initial value as the Start Date
// With an increment of 1 day on each loop
// With condition current value of loop is smaller than or same as end date
for (DateTime i = startDateInUTC;
i.isBefore(endDateInUTC) || i.isAtSameMomentAs(endDateInUTC);
i = i.add(const Duration(days: 1))) {
// Converting back UTC date to Local date if it was local before
// Or keeping in UTC format if it was UTC
if (startDateTime.isUtc) {
daysInFormat.add(i);
} else {
daysInFormat.add(DateTime(i.year, i.month, i.day));
}
}
return daysInFormat;
}
Yes, you can send disabled dates into the component.
Check this sample of the documentation.
For further options, check the whole docs.
I use Yii2 framework and I have a column named "datacreation" (type DATE TIME and value CURRENT TIMESTAMP).
Also, I have this code in my view:
[
'attribute' => 'datacreazione',
'value' => function ( $model ) {
$stampa= "";
if( $model->Utenteupdate ){
$tip1= $model->Utenteupdate;
$tip1= ($tip1) ? User::findOne($tip1) : null;
$tip1n= ($tip1) ? $tip1->id : "";
$stampa= ($tip1n);
}
return $model->datacreazione." utente ".$stampa;
},
'label' => 'Data creazione']
This show me the result: "2020-07-15 11:33:00 utente 734".
Now, I would to hide the date and the timestamp. At the end, the result that I wish is "utente 734", without other information about date and time. I hope to be clear.
Anyone can help me with this code please?
Thank you!!!!
You build the showed text in one anonymous associated to the param value
then in this anonymous function just return the string for utente 734
return "utente ".$stampa;
What I want to accomplish is to trigger an event when the user selects a date from a date input field in HTML using KnockoutJS. Regardless of the date the user chooses, I want to set the first day of the selected month.
I don't want to post the date field on a form yet. I want the event to be triggered when the user just selects the date from the input field.
If you bind the value of the date input to an observable, you can subscribe to changes on that observable and change the value to the first day of the selected month.
This is more straightforward than the answer that I had previously written here.
const vm = {
theDate: ko.observable('')
};
vm.theDate.subscribe(function(newValue) {
vm.theDate( newValue ? newValue.replace(/\d\d$/, '01') : '');
});
ko.applyBindings(vm);
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.4.2/knockout-min.js"></script>
<input type="date" data-bind="value: theDate">
I currently use GF for reservations 'Arrive' and 'Departure'. I would like the date displayed on the 'Departure' to always be one date ahead of the 'Arrival' date, regards of what date the guest picks. Then can pick a custom 'Departure' date, but as a default I'd like to show one date forward of the 'Arrival' date no matter what 'Arrival' date they choose.
This is possible with the gform_datepicker_options_pre_init JS filter. Example #3 is what you're after:
gform.addFilter( 'gform_datepicker_options_pre_init', function( optionsObj, formId, fieldId ) {
if ( formId == 12 && fieldId == 8 ) {
optionsObj.minDate = 0;
optionsObj.onClose = function (dateText, inst) {
jQuery('#input_12_9').datepicker('option', 'minDate', dateText).datepicker('setDate', dateText);
};
}
return optionsObj;
});
If you're looking for a code-less solution, I've written a plugin that let's you do this in just a few clicks called GP Limit Dates.
Also, here is an article that addresses your specific need: How to restrict dates in second date field based on date selected in first date field with Gravity Forms
I'm relatively new to Drupal 7 and I'm trying to create a custom webform. My goal is to add a date (provided by the date module) field with out the day option. So it displays on month and year hiding the day option.
I have managed to achieve this but only by recreating the wholedate field as a custom field but I wanted to know if it was possible to customize the date field provided by the date module.
Below is a screen shot of my form:
How I create my custom date field:
function my_webform_form_alter(&$form, &$form_state) {
if (isset($form['#node']->webform) && $form['#node']->uuid == '00b20537-d5ce-45c2-af37-150c9e73b96d') {
//$form['submitted']['date']['#type'] = 'hidden';
$form['ggg'] = array(
'#type' => 'date_select',
'#title' => 'Date',
'#date_format' => 'm/Y',
'#default_value' => date('Y-m-d')
);
}
}
I have tried other methods on hiding the field components but nothing seem to work so far. I was wondering if I needed to implement a hook different from the alter hook (the one being used).
Any suggestions on how to achieve this?
A possible solution would be to transform the day field of the date component to a hidden field instead of the select field type. That can be achieved by adding a #process callback for that field and altering the data.
function YOURMODULE_form_alter(&$form, &$form_state, $form_id)
{
// Your logic here depending which form to alter
// ...
// Add #process for the component with key name 'date'
$form['submitted']['date']['#process'][] = 'YOURMODULE_process_date';
}
function YOURMODULE_process_date(&$element)
{
// change type to hidden
$element['day']['#type'] = 'hidden';
// set value to first day of the month
$element['day']['#value'] = '1';
return $element;
}
Webform now allows hiding the day, month or year of a date. See this issue for details.