How do I trigger an event in Knockout JS for a date input? - date

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">

Related

Display holidays on antd's datepicker

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.

Wordpress GravityForm autosubmit with a parameter

I have a requirement to auto-submit a GravityForm with a form parameter. So, as far as I know GravityForms has the ability for you to send a parameter through the URL and it'll automatically fill out a field for you. What I want to do is the ability to send another field called autosubmit=true in which if that is on there, it will automatically submit the form.
Here is a generic solution for any form: Automatically submit a form
And here is a Gravity Forms specific solution: https://www.gravityhelp.com/forums/topic/autosubmit-with-gravity-forms
The basic premise of both is that you use Javascript to trigger the form submission when the page loads. You would need to make yours conditional so that it checks the value of your pre-populated autosubmit field.
<script>
jQuery( document ).ready( function() {
// Update "1" to your form ID and "2" to your prepop field ID
if( jQuery( '#input_1_2' ) == 1 ) {
// Update "1" to your form ID
jQuery( 'form#gform_1' ).trigger( 'submit' );
}
} );
</script>

Gravity Forms Date Push Reservations

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

Webform form alter date hide day

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.

In yii how to find date is greater than current date

I am working in Yii framework. I am having Poll table with fields as-
-pollId
-pollQuestion
-Isactive
-publishDate
-isPublish
when new poll is created,that date get inserted into publishDate field.
e.g.2012-04-04 02:23:45 In this format entry get inserted.
Now i want to check weather this publishDate is smaller than today's date or current date. i.e.publishDate should not be greater than current date.
So how to check this in yii? Please help me
As per normal PHP. Assuming $model is the submitted form and you have assigned (after the form has been submitted) $model->attributes = $_POST['MyModel']
You can then use:
if ($model->publishDate < date('Y-m-d H:i:s')){
// it is smaller
}
Another thing you could look at is using Yii's model validation. You could store the created date (which would be todays date) and then compare that to the publishDate in the form submit:
$model->created = date("Y-m-d H:i:s");
if ($model->validate){
...
}
And in your Poll model:
array('publishDate ','compare','created','operator'=>'<', 'message'=>'Publish Date must be smaller than the current date'),