Jump to content

datetime inputfield within custom inputfield - datepicker does not work


gunter
 Share

Recommended Posts

For a custom fieldtype/inputfield that contains two datetime variables (start + end) I want use two datetime inputfields in the render method.
Everything works, except the datepicker does not appear... does anybody know why?

	public function ___render() {

		$name = $this->attr('name');
		$value = $this->attr('value');
		
		//getting values for start and end
		$start 	= $value->data["start"]->toDateTimeString();;
		$end 	= $value->data["end"]->toDateTimeString();

		//preparing inputfield
		$field = $this->modules->get('InputfieldDatetime');
		$field->set("label", __("Date"));

		$field->attr("class", "uk-form-width-medium ");
		$field->required = true;
		$field->datepicker = InputfieldDatetime::datepickerClick;
		$field->dateInputFormat = 'Y-m-d';
		$field->timeInputFormat = 'H:i';
		$field->timeInputSelect = 1;

		//setting first inputfield
		$field->attr("id+name",$name."_start");
		$field->attr("value",$start);		
		$renderedFieldStart = $field->render();

		//setting second inputfield
		$field->attr("id+name",$name."_end");
		$field->attr("value",$end);
		$renderedFieldEnd = $field->render();

		$out = $renderedFieldStart.$renderedFieldEnd;

		return $out; 
	}

 

Link to comment
Share on other sites

ok, thanks elabx for the hint to look at this..
I compared the html output against a working datetime inputfield...
the solution is, I have to set the class by hand... I tought it works automatically by setting $field>datepicker... but thats not true
 

		$field->attr("class", "FieldtypeDatetime InputfieldDatetimeDatepicker InputfieldDatetimeDatepicker1"); // I have to set the datepicker class by hand (1, 2 or 3)

		$field->datepicker = InputfieldDatetime::datepickerClick; // this is not needed, because it´s not working

so... I have a working date/time picker now, by setting the right class like this

  • Like 2
Link to comment
Share on other sites

  • 1 year later...

I experienced the same. Just loading the InputfieldDatetime module does not apply the required classes to initialize the datepicker. I also had to manually load the module assets from InputfieldDatetime module. They were not loaded automatically by loading the module. This is my working code:

        $f = $this->modules->get('InputfieldDatetime'); // load module
        $this->config->scripts->add($this->config->urls->modules . 'Inputfield/InputfieldDatetime/InputfieldDatetime.js'); // load module assets
        $this->config->styles->add($this->config->urls->modules . 'Inputfield/InputfieldDatetime/InputfieldDatetime.css'); // load module assets
        $f->attr('name', 'deliverydate-' . $id);
        $f->addClass('FieldtypeDatetime InputfieldDatetimeDatepicker InputfieldDatetimeDatepicker1'); // manually assign classes
        $f->label = ('Lieferdatum');
        $f->inputType = 'text';
        $f->datepicker = \ProcessWire\InputfieldDatetime::datepickerFocus; // this does not work. datepicker widget does not appear on focus
        $f->dateInputFormat = 'd.m.Y';

Another little thing that I could not get to work is triggering the datepicker on focus of the inputfield. My field looks like this and the user has to click the calendar icon to make the datepicker appear.

InputfieldDatetime.png.b6719e6c0e8d68f86b37a5762b87392a.png

Link to comment
Share on other sites

8 hours ago, gebeer said:

Another little thing that I could not get to work is triggering the datepicker on focus of the inputfield. My field looks like this and the user has to click the calendar icon to make the datepicker appear.

Works here just fine. I don't even have to manually load its assets. All of the below work.

<?php

$field = $this->modules->get('InputfieldDatetime');
$field->inputType = 'text';
$field->datepicker = 3;
// $field->datepicker = \ProcessWire\InputfieldDatetime::datepickerFocus;
//$field->datepicker = InputfieldDatetime::datepickerFocus;

 

 

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