Jump to content

Set minDate in Datepicker


cpx3
 Share

Recommended Posts

I have a (Formbuilder) form that contains two datefields, each of them with a datepicker. The first datefield should have today as the minimum date (no date selectable before today), the second one should have the date from field1 plus 1 day as a minimum. Any ideas how I could achieve that?

Thanks! 

Link to comment
Share on other sites

@cpx3 you could select the html5 native date field as your type and choos today as your default value.
Your minimum values can be set via a hook

$wire->addHookBefore('FormBuilderProcessor::renderReady', function($event) {

	$form = $event->arguments(0);
	if($form->name != 'your-form-name') return;

	$inputfield_1 = $form->getChildByName('your_date_field_1');
	$inputfield_2 = $form->getChildByName('your_date_field_2');

	if($inputfield_1) $inputfield_1->attr('min', date('Y-m-d'));
	if($inputfield_2) $inputfield_2->attr('min', date('Y-m-d', strtotime(' +1 day')));

});


 

Link to comment
Share on other sites

First, a million thanks. The only thing is that neither this works, as the HTML datepicker seems to ignore the value and shows all dates. I wonder seriously why Ryan decided to cut this function from the datepicker (at least with the paid FormBuilder module), as with Javascript it would work...

Link to comment
Share on other sites

  • 3 weeks later...

All good now?

  

On 3/23/2024 at 11:33 PM, ngrmm said:

@cpx3 you could select the html5 native date field as your type and choos today as your default value.
Your minimum values can be set via a hook

$wire->addHookBefore('FormBuilderProcessor::renderReady', function($event) {

	$form = $event->arguments(0);
	if($form->name != 'your-form-name') return;

	$inputfield_1 = $form->getChildByName('your_date_field_1');
	$inputfield_2 = $form->getChildByName('your_date_field_2');

	if($inputfield_1) $inputfield_1->attr('min', date('Y-m-d'));
	if($inputfield_2) $inputfield_2->attr('min', date('Y-m-d', strtotime(' +1 day')));

});


I want to set minDate in Datepicker and for that I am searching for the information online. All good now? Please reply to me as soon as possible. I am waiting for your response and till then I will visit https://academized.com/cheap-book-report here because over there I found an essay writer who write a book report for me at a cheap price. I don't have enough money with me and that is why I was searching for the cheap essay writer online.

Edit: It works for me.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...