Get KoolPHP UI with 30% OFF!

DateTimePicker telling invalid date at client side

Jayme
Hello,
Before the last update of KoolPHPSuite setting values to DateTimePicker at client side was working fine using
form.datetimepickerobj.value = date.toLocalString();

Now I am getting a message on the value part of the object saying "Invalid Date", no matter I use toLocalString() or toUTCString().
How can I set values from client side to the component ?
Thank you very much.
Best regards.
Jayme Jeffman
Posted Jun 27, 2017 Kool
Anthony Amolochitis
Did you use the javascript method unescape() to decode the string data?
https://www.w3schools.com/jsref/jsref_unescape.asp
Posted Jun 27, 2017 Kool
Jayme
Hi Anthony,
No, I don't, it was not necessary before. How should I use it ? I am using Localization = 'pt-br'.
The toLocalString() returns a string just like "15/12/2017 18:11:23".
Posted Jun 27, 2017 Kool
Anthony Amolochitis
I wasn't sure what the return values were from the calendar, but I thought maybe the date string may be encoded with HTML entities.
Posted Jun 27, 2017 , edited Jun 27, 2017 Kool
Jayme
I am not making any POST request, just using JavaScript, so I think IMHO there is no any encoded string.
I do not know why this control do not have a JavaScript setValue method correspondent to the same in PHP.
Posted Jun 27, 2017 , edited Jun 27, 2017 Kool
Anthony Amolochitis
Probably a good request for the KoolPHP team huh.
Posted Jun 27, 2017 Kool
David
Hi Jayme,
Would you please post your PHP and Javascript code when creating and setting KoolDateTimePicker? Thanks!
Posted Jun 29, 2017 Kool
Jayme
Hi David,
Here goes the code that matters:
<cut>
 // Calendarios
  $data->setDate(date('Y'),date('m'), date('d'));
  $data->setTime( 23, 59, 59); //zero hora
  //echo  $data->format('d/m/Y H:i:s');   exit;
  $dtFiltIni = new KoolDateTimePicker("dtFiltIni"); //Create calendar object
  $dtFiltIni->scriptFolder = $KoolControlsFolder."/KoolCalendar";//Set scriptFolder
  $dtFiltIni->Localization->Load($KoolControlsFolder."/KoolCalendar/localization/pt_br.xml");
  $dtFiltIni->styleFolder="default";
  $dtFiltIni->DateFormat = "d/m/Y";
  $dtFiltIni->TimeFormat = "H:i:s";
  $dtFiltIni->TimeViewSettings->TimeFormat = "H:i:s";
  $dtFiltIni->TimeViewSettings->Interval = mktime(0,15,0); // Every 15 minutes
  $dtFiltIni->TimeViewSettings->HeaderText = "Hora In&iacute;cio";
  $dtFiltIni->Width = "170px";
  $dtFiltIni->CalendarSettings->ShowRowHeader=false;
  $dtFiltIni->CalendarSettings->ShowDayCellToolTips = false;
  $dtFiltIni->CalendarSettings->ShowToday = true;
  $dtFiltFim = new KoolDateTimePicker("dtFiltFim"); //Create calendar object
  $dtFiltFim->scriptFolder = $KoolControlsFolder."/KoolCalendar";//Set scriptFolder
  $dtFiltFim->Localization->Load($KoolControlsFolder."/KoolCalendar/localization/pt_br.xml");
  $dtFiltFim->styleFolder="default";
  $dtFiltFim->DateFormat = "d/m/Y";
  $dtFiltFim->TimeFormat = "H:i:s";
  $dtFiltFim->TimeViewSettings->TimeFormat = "H:i:s";
  $dtFiltFim->TimeViewSettings->Interval = mktime(0,15,0); // Every 15 minutes
  $dtFiltFim->TimeViewSettings->HeaderText = "Hora T&eacute;rmino";
  //$dtFiltFim->TimeViewSettings->
  $dtFiltFim->Width = "170px";
  $dtFiltFim->CalendarSettings->ShowRowHeader=false;
  $dtFiltFim->CalendarSettings->ShowDayCellToolTips = false;
  $dtFiltFim->CalendarSettings->ShowToday = true;
  $dtFiltFim->Value = $data->format('d/m/Y H:i:s'); // <= this is working fine
  $data->sub(date_interval_create_from_date_string(($data->format('d')-1).' days'));
  $data->setTime(0,0,0);
  $dtFiltIni->Value = $data->format('d/m/Y H:i:s'); // <= this is working fine
  $dtFiltIni->Init();
  $dtFiltFim->Init();
<cut>
// Here is the problem
      function pageLoad(){
        var blk = null;
        var sData;
        var theForm;
        //var dataIni = null;
        justNow = new Date();
        dataIni = new Date(justNow.getFullYear(),justNow.getMonth(), justNow.getDate() - 2,0,0,0,0);
        if( dtFiltIni && dtFiltFim ){
          theForm = document.getElementById("filtevt");
          theForm.dtFiltIni.value = dataIni.toLocaleString() ;
          theForm.dtFiltFim.value = justNow.toLocaleString();
        }
        else  alert("Not objects");
<cut>
<!-- render the controls -->
<form id="filtevt" action="" style="margin: 0px 0px 0px 10px; height:100%; width: 150px; font-size:10pt;">
<label for="dtFiltIni" style="margin: 2px 0px 0px 0px; float: left; ">De : </label><div style="display: inline-block; margin: 0px 15px 0px 0px; width: 180px; height: 25px; border: none; float: right;"><?php echo $dtFiltIni->Render(); ?></div><br>
<label for="dtFiltFim" style="margin: 14px 0px 0px 0px; clear: both; float: left; ">Até: </label><div style="display: inline-block; margin:10px 15px 0px 0px; width: 180px; height: 25px; border: none;  float: right;"><?php echo $dtFiltFim->Render(); ?></div><br>
</form>

I hope you can find the problem.
While I have not other solution I am setting the Date and Time value of the control in the PHP code, but I need to refresh the date and time of dtFiltFim periodically to have it updated to the current date and time every time some event is fired.
Thanks!
Best regards.
Posted Jun 29, 2017 Kool
David
Hi Jayme,
which line of code caused error:
theForm.dtFiltIni.value = dataIni.toLocaleString() ;
or:
theForm.dtFiltFim.value = justNow.toLocaleString();
theForm.dtFiltIni or theForm.dtFiltFim is just the text input element of KoolDateTimePicker. When you find the line of error, could you please check which part (toLocaleString() or the value setting) is the problem? Thanks!
Posted Jun 30, 2017 Kool
Jayme
Hi David,
Never mind, it was my fault. I apologize for making you wasted your time on this matter.
As I have made a complete code for you, when testing it I have found that everything was working fine, so I decided to recheck my code and now it is ok. I think I migth have made a typo on the code so the value passed to the control was wrong.
Thank you very much.
Thank you also for showing me a JavaScript feature I didn't know, the console object which I have never used, now I am using it to help debugging my code without having to pop up alert messages.
Best regards
Posted Jun 30, 2017 Kool -