Column with text U//PR is causing an error

Column with text U//PR is causing an error

snunnsnunn Posts: 17Questions: 5Answers: 0

I get the following error when I have a key that has a // in it. What/how should the fields be encoded to avoid this? The error is below.

datatables.min.js:14 Uncaught Error: Syntax error, unrecognized expression: #U//PR
at Function.fa.error (datatables.min.js:14)
at fa.tokenize (datatables.min.js:14)
at fa.compile (datatables.min.js:14)
at fa.select (datatables.min.js:14)
at fa (datatables.min.js:14)
at Function.fa.matches (datatables.min.js:14)
at Function.n.filter (datatables.min.js:14)
at z (datatables.min.js:14)
at n.fn.init.filter (datatables.min.js:14)
at datatables.min.js:139

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,726Questions: 1Answers: 10,110 Site admin

    Thanks for your question - however, per the forum rules can you link to a test case showing the issue please. This will allow the issue to be debugged.

    Information on how to create a test page, if you can't provide a link to your own page can be found here.

    Thanks,
    Allan

  • snunnsnunn Posts: 17Questions: 5Answers: 0
    edited April 2017

    This only happens when I update a row in the editor with a key(ie, idSrc) that has a // in it. The request is sent to the server for the update, the row is updated correctly in the db, and the response comes back and then the editor fails trying to update the row and produces the error above.

    I don't use "DT_RowId" for the identifying the rows, but instead specify the idSrc: and use the key from the database in the code. As long as the idSrc key doesn't have a / in it, everything works fine. I have tried escaping the "/"'s but that didn't help. If I remove them, then things work.

  • allanallan Posts: 61,726Questions: 1Answers: 10,110 Site admin

    Thanks for the additional information. Yes, I can see how using a / in the primary key would cause an issue since Editor will use a DOM selector with that id to try and get the row node and that makes it an invalid CSS selector.

    There isn't currently a workaround for that I'm afraid (other than to use only valid CSS selectors for the id). I will look into this for the next release.

    Regards,
    Allan

  • snunnsnunn Posts: 17Questions: 5Answers: 0
    edited April 2017

    I am hitting a legacy db that I can't change. Could you point me to the area of the code I would need to change how the dom selector is used?

  • allanallan Posts: 61,726Questions: 1Answers: 10,110 Site admin

    Let me get back to you on this one - hopefully tomorrow. I'll take a look at it and trace it through to see what the correct way to handle this is.

    Thanks,
    Allan

  • snunnsnunn Posts: 17Questions: 5Answers: 0

    Thanks for taking a look. Hopefully there is an alternate way to look the field up.

  • snunnsnunn Posts: 17Questions: 5Answers: 0

    Any luck on this?

  • allanallan Posts: 61,726Questions: 1Answers: 10,110 Site admin
    Answer ✓

    Sorry for the delay. Yes, this is a bug in Editor. To try and speed up the selection of the row(s) that have been altered it does an id select, but that can result in a syntax error from Sizzle if the id format doesn't match what Sizzle allows for an id.

    To fix this find the following line in the Editor code:

                    row = dt.row( __dtjqId(rowId) );
    

    and replace with:

                try {
                    row = dt.row( __dtjqId(rowId) );
                }
                catch (e) {
                    row = dt;
                }
    

    That will resolve the issue as there is already fallback code to look the id up using a slower method if it wasn't found by id. It just wasn't handling the error situation.

    This will be in the next release of Editor. Thanks for flagging this up!

    Regards,
    Allan

  • snunnsnunn Posts: 17Questions: 5Answers: 0

    Allan,

    Thanks for the code. I also had to update the commit: function to have the same try/catch.

  • DavidT72DavidT72 Posts: 2Questions: 0Answers: 0

    I had the same issue where an email address was used as the ID. This fix addressed it.

    Thanks,
    Dave

This discussion has been closed.