Datetimepicker (2) Plugin Issues

Datetimepicker (2) Plugin Issues

rclaytonrclayton Posts: 10Questions: 3Answers: 0

I'm attempting to retrofit a generator-created DataTables/Editor tool to use the Datetimepicker Bootstrap plugin referenced here: http://editor.datatables.net/plug-ins/field-type/editor.datetimepicker-2 and I guess I'm missing something important because I cannot seem to get the model to synch with the view.

Here's what I had using the default "generated" code (truth be told I added a leftjoin table but that seems to work):

http://geofactual.com/test2/enterpostcal/

Here's the same code but I added the bits for implementing the datetimepicker-2

http://geofactual.com/test1/enterpostcal/

(I understand that having test1 be more advanced than test2 is illogical ... it's been a long day)

Symptoms of dysfunction: when editing an existing record the Date and the TIme field don't have any data from the record in the db.

Similarly when creating a new record the Date (fsdb_postcal_intake.postcal_date) is empty in the load sent to table.fsdb_postcal_intake.php and returns this error:

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'postcal_date' cannot be null

because that's a required field on our db.

ps. I've tried running the debugger but I'm not sure how long that should take ... it's taking a very long time (possibly it's so buggy the debugger is tired too).

I don't understand "where the model is" if it is not in the form ... and as such, I'm guessing that the controller "selector" code is not accessing these elements because they are wrapped in the grouping divs but I'm hoping you'll see the error much faster than I will suss it out.

This is my second day of working with DataTables/Editor and I like the product and the support information I've seen. Thanks in advance and so forth. :)

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,744Questions: 1Answers: 10,111 Site admin
    Answer ✓

    Hi,

    I'm afraid it looks like a bug in the plug-in code is at least partly to blame. I've updated the code now and it would be great if you could grab the latest version.

    Having said that, that is not the entire problem. The other issue is that the date format that is being returned by the server is not the same format as that for the date time picker. Because they are different, when Editor tries to set the date, the date time picker goes "I don't know what to do with that" and throws it away!

    So the two need to be aligned.

    It looks like the date time picker has the option of setting a format via the data-date-format option. I've added support for that in the updated plug-in, so you might do something like:

       type: 'datetime',
       attr: {
          "data-date-format": "YYYY-MM-DD"
       }
    

    You can use a nicer format of course - it just need the server to send back and accept the same format. Consistency is the key there.

    Thanks,
    Allan

  • rclaytonrclayton Posts: 10Questions: 3Answers: 0

    Hmm ... I think I've gotten the consistency thing worked out but there's something about the call to moment.js (from datepicker) that is forcing an error (undefined is not a function) which leads me to believe that I need to give a format to the date when it is being submitted ("get" function).

    http://geofactual.com/test1/enterpostcal/

    value of "conf._input.data("DateTimePicker").getDate()" looks like this: 1401865200000

    Please consider ... I'll understand if this is not an Editor issue ...

    Rob

  • rclaytonrclayton Posts: 10Questions: 3Answers: 0
    edited May 2014

    From the "DateTime heals all wounds" department.

    client-code: (had to slightly modify your plugin to avoid the dateTimePicker "freakout" about having to format the native timestamp and asking moment.js for something improperly ^^).

    so where you wrote:
    return conf._input.data("DateTimePicker").getDate();

    I modified:

      return conf._input.data("DateTimePicker").getDate().format('YYYY-MM-DD HH:mm:ss');
    

    And then I was having a bit of a bear getting the right values in or out of the DB because I was using "date_format_to_sql" and "date_sql_to_format".

    Needed to forgo the setFormatter and modify the getFormatter (from the basic generator boilerplate).

    server-side:
    /*
    Field::inst( 'FSDB_POSTCAL_INTAKE.postcal_date' )
    ->validator( 'Validate::dateFormat', array('empty'=>false, 'format'=>'m/d/Y H:i' ) )
    ->getFormatter( 'Format::datetime', array( 'from' => 'Y-m-d H:i:s', 'to' => 'm/d/Y H:i') )
    //->setFormatter( 'Format::datetime', array( 'from' => 'Y-m-d H:', 'to' => 'Y-m-d H:i:s'))
    */

    Pretty proud o' myself ... and realize I know very little. Thank you for the support, hope this helps others.

    Rob Clayton

  • allanallan Posts: 61,744Questions: 1Answers: 10,111 Site admin

    Hi Rob,

    Nice one! Great to hear you managed to resolve the issue and thanks for sharing your solution with us! I'm sure it will help others - it certainly helps me :-)

    Regards,
    Allan

  • MattDMattD Posts: 27Questions: 2Answers: 0

    Thanks for posting this Rob, I was also running into the issue with the moment.js. I will give this a shot!

This discussion has been closed.