Editor 2, empty datetime issue ('Invalid date')

Editor 2, empty datetime issue ('Invalid date')

stephanbstephanb Posts: 36Questions: 11Answers: 0
edited March 2021 in Free community support

Just updated my codebase to Editor 2 and I noticed that it doesn't like empty datetime fields even in fields that don't change.
Look at this example: http://live.datatables.net/tebebuzo/13/edit

If you change the "Need by date" for "Package 2" to something else, the empty date field in the same row triggers the following form submission:

data[235][3]: 0
data[235][6]: 2021-04-21
data[235][7]: Invalid date
action: edit

How can I keep the 'Invalid date' from happening?

This question has accepted answers - jump to:

Answers

  • stephanbstephanb Posts: 36Questions: 11Answers: 0

    I noticed that when you click on "New Package", the modal also initializes with 'Invalid Date'

  • MachineMachine Posts: 1Questions: 0Answers: 0

    I had the similar issues in v1.9, I've written my own plugin for datetime fields now.

    I couldn't get your example to submit to be able to test, but if you try to render an empty date field with moment it returns 'Invalid date' or 'Invalid format'

    Try checking if there is a date to render and set it to null if it is empty. I render like this.

    render: function ( data, type, row ) {
        return (data)
            ? moment(data, "YYYY-MM-DD").format("DD/MM/YYYY")
            : null;
    },
    
  • stephanbstephanb Posts: 36Questions: 11Answers: 0

    I tried to get this to work but I still get the same error. Have a look here: http://live.datatables.net/tebebuzo/16/edit

    You can see the HTTP POST info by firing up your browser development settings (F12) and then watching the Network traffic. Once you see the call to /packages, click on it and scroll to the bottom. You'll see what it's trying to send to the server.

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    Answer ✓

    Hi,

    I'm afraid you've discovered a bug that we missed in development here. There isn't an external workaround, but if you are comfortable making a small change in the Editor source code, search for:

    conf._picker.val( typeof val === 'string' && val.indexOf('--') !== 0 && conf.wireFormat && moment ?
    

    and replace with:

    conf._picker.val( typeof val === 'string' && val && val.indexOf('--') !== 0 && conf.wireFormat && moment ?
    

    That will fix it and I'll include that in the Editor 2.0.2 patch release. If you prefer, let me know and I'll send over the updated file.

    Thanks,
    Allan

  • stephanbstephanb Posts: 36Questions: 11Answers: 0
    edited March 2021

    Thanks. It worked for me. I'll download a new bundle when you push the patch release out. Just let us know.

  • stephanbstephanb Posts: 36Questions: 11Answers: 0

    @allan Please let me know when you've updated the live environment with 2.0.2. I may have another bug for you, but I need to replicate it there first.

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin

    2.0.2 is probably a week or two away as 2.0.1 only just dropped this week. Are you able to describe the issue and I'll try to replicate it here.

    Thanks,
    Allan

  • stephanbstephanb Posts: 36Questions: 11Answers: 0
    edited March 2021

    Look at this: http://live.datatables.net/tebebuzo/19/edit
    This isn't date related.

    When I make a change and trigger a submit I see the data sent to the server.
    I process it and send back the json. What I then see in the browser's dev console is this:

    Uncaught TypeError: Cannot read property 'getDetails' of undefined
        at _Api.<anonymous> (datatables.js:102966)
        at Object.getDetails (datatables.js:66884)
        at Editor.commit (datatables.js:76223)
        at Editor._dataSource (datatables.js:79149)
        at Editor._submitSuccess (datatables.js:80206)
        at datatables.js:80059
        at Object.opts.complete (datatables.js:78865)
        at c (jquery-3.6.0.min.js:2)
        at Object.fireWith (jquery-3.6.0.min.js:2)
        at l (jquery-3.6.0.min.js:2)
    

    At that point the datatables table locks up.

    This applies to the multi-field-edits new in Editor 2, but it also happens with the normal inline edit setup.

  • stephanbstephanb Posts: 36Questions: 11Answers: 0

    @allan have you had a chance to look at this stack trace yet?

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin

    Hi,

    Apologies for having not been able to get back to you yesterday. I'm not able to reproduce the error you are seeing in the live page (due to the 404 on the submission), but the error you are getting relates to these lines in Editor:

                if ( dtAny.searchBuilder !== undefined && typeof dtAny.searchBuilder.rebuild === 'function' && ! ssp ) {
                    dtAny.searchBuilder.rebuild(dtAny.searchBuilder.getDetails());
                }
    

    Do you have SearchBuilder on your page and initialised in the table? It isn't there in the live example, and if you don't on your actual page, I'm not clear on how that could get getting triggered. Any chance of PM'ing me a link to your actual page?

    Allan

  • kthorngrenkthorngren Posts: 21,352Questions: 26Answers: 4,955

    Uncaught TypeError: Cannot read property 'getDetails' of undefined

    Searching for that error yields this thread and this thread. See if they help.

    Kevin

  • stephanbstephanb Posts: 36Questions: 11Answers: 0
    edited March 2021

    I am not using SearchBuilder but I had it in my bundle. Removing it from my bundle did make the error go away. Unfortunately that doesn't help @allan to fix the underlying issue.

    My site is not publicly accessible, so unfortunately I can't send him a link either.

  • kthorngrenkthorngren Posts: 21,352Questions: 26Answers: 4,955
    Answer ✓

    but that won't help you track down the bug.

    The problem with the error Uncaught TypeError: Cannot read property 'getDetails' of undefined has been fixed and is in the nightly builds.

    Kevin

  • axel_tsysaxel_tsys Posts: 19Questions: 5Answers: 0

    Hello,
    it looks like the issue is back in version 2.0.5.
    With 2.0.4 my code is working.
    The version 2.0.5 set en empty date date value in the sql string to ''

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin

    @axel_tsys - Are you using the ifEmpty() formatter or anything else at the server-side to convert the empty string to null?

    Allan

  • axel_tsysaxel_tsys Posts: 19Questions: 5Answers: 0
    edited December 2021

    No, I did not use any formatter at this point.
    Until now it was not necessary.
    But I have set this now and it is working as expected.
    Thanks Alan

Sign In or Register to comment.