Error when editing row with natural key containing @

Error when editing row with natural key containing @

blabablabablabablaba Posts: 47Questions: 19Answers: 0

When using a Natural Key such as an email address, the editor sends the data ok:

{
    action:"edit"
    data:{name@oldaddress.com:
        {user_ID: "999999999", email_ID: "name@newaddress.com"}
    }
}

The server updates the the email address and responds to the client with:

{
    data: [
        {email_ID: "name@newaddress.com", odr: "1", dft: "0", verified: "1"}
    ]
}

All good so far.

HOWEVER, when parsing the returned data, datatables issues the following error:

datatables.min.js:14 Uncaught Error: Syntax error, unrecognized expression: #name@oldaddress.com

Testing:

If the email address has a backslash inserted before the @, then the error goes away so:

name\@oldaddress.com - CAN BE UPDATED FINE
name@oldaddress.com - THROWS ERROR IN THE CLIENT

Is the solution to this to have Datatables escape the '@' symbol?

Replies

  • blabablabablabablaba Posts: 47Questions: 19Answers: 0
    edited December 2017

    .

  • blabablabablabablaba Posts: 47Questions: 19Answers: 0

    name@oldaddress.com

    should read:

    name@oldaddress\.com

    I forgot to double-escape.

  • allanallan Posts: 63,457Questions: 1Answers: 10,465 Site admin

    Thanks for letting me know about that. There was an error in the post Ajax handling in Editor for it handles id elements which special characters. I've committed the fix now and it will be in 1.7.1, which will be release in January. Until then, I can send you a 1.7.1-dev version with the fix - is the e-mail address for your forum account the one to use?

    Thanks,
    Allan

  • blabablabablabablaba Posts: 47Questions: 19Answers: 0
    edited December 2017

    Hi Allan,

    Thanks!

    I managed a workaround for which involved adding slash to the database output, and in datatables I put:

        editor.field( 'email_ID' ).input().on( 'focus', function () {
    
            editor.field( 'email_ID' ).set(editor.field( 'email_ID' ).val().replace(/\\/g, ""));
    
        } );
    

    And separately in DataTable() columns: I put a render:

                        return data.replace(/\\/g, "");
    

    The above ensured that the index kept the escaped @, the table displayed the unescaped @ and the editor field also provided the unescaped @.

    While it took me a while to figure out, I feel I learned a lot about DT in the process. Your fix will allow me to exit elastic band mode!

    Thanks - yes I do use the same email, please do send!

    Steve

This discussion has been closed.