Hello!
These errors are output to the Chrome console.
message : "ERROR SyntaxError: Failed to execute 'querySelector' on 'Element':'[]' is not a valid selector."
function name : "ListBox.prototype.setSelection = function (values, isSelect, isText)"
code : "li = _this.list.querySelector('[data-value="' + text.replace(/"/g, '\\"') + '"]');"
I think it's a new line in the parameter text in the querySelector, "\n""I think there's a problem going in.
angular : 17.1.2
syncfusion : 24.2.4
Hi Leprintemps,
We have validated your reported query with Listbox and the specific version. But we are unable to reproduce the issue on our end. Refer to the below sample link.
Sample link: https://stackblitz.com/edit/angular-zzrsmdyz?file=package.json
If you are still facing the issue, kindly share the issue-replicating sample or replicate the issue in our sample with a screenshot of the error or a video demonstration. Based on that, we will check and provide the solution.
Regards,
YuvanShankar A
If so, can you tell me how to put a new line in "listbox"?
Hi Leprintemps,
We have checked your scenario with shared function name with code line and confirmed the issue as “Script error thrown while setting the values has a new line (n) in the list item text of the list box" and logged a defect report. We will include the fix for this issue in the upcoming weekly patch release scheduled for the First week of April 2025.
Feedback link: https://www.syncfusion.com/feedback/66255/script-error-thrown-while-setting-the-values-has-a-new-line-n-in-the-list-item
You will be informed regarding this once the fix is published.
Disclaimer: “Inclusion of this solution in the weekly release may change due to other factors including but not limited to QA checks and works reprioritization.”
Regards,
YuvanShankar A
You're right—the newline \n in text breaks querySelector. Sanitize input to remove or escape it first.
Hi Leprintemps / John Cole,
We would like to inform you that we have resolved the reported issue "Script error thrown while setting the values has a new line (n) in the list item text of the list box" in our latest version 29.1.37. Therefore, we recommend that you update your package to the latest version to resolve the current problem.
Release notes: https://ej2.syncfusion.com/angular/documentation/release-notes/29.1.37?type=all#listbox
Sample: https://stackblitz.com/edit/angular-zzrsmdyz-6ygnpgnu?file=package.json
Root cause: The querySelector function does not get the value based on new line char(\n) with data-value attributes in li elements.
Regards,
Priyanka