gunter Posted August 17, 2019 Share Posted August 17, 2019 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 More sharing options...
elabx Posted August 18, 2019 Share Posted August 18, 2019 Does it render with InputfieldDateTimeDatePicker class to initialize? Are the Inputfield scripts loaded? Link to comment Share on other sites More sharing options...
gunter Posted August 18, 2019 Author Share Posted August 18, 2019 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 2 Link to comment Share on other sites More sharing options...
gebeer Posted July 21, 2021 Share Posted July 21, 2021 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. Link to comment Share on other sites More sharing options...
kongondo Posted July 21, 2021 Share Posted July 21, 2021 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now