Column with text U//PR is causing an error
Column with text U//PR is causing an error
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
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
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.
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
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?
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
Thanks for taking a look. Hopefully there is an alternate way to look the field up.
Any luck on this?
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:
and replace with:
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
Allan,
Thanks for the code. I also had to update the commit: function to have the same try/catch.
I had the same issue where an email address was used as the ID. This fix addressed it.
Thanks,
Dave