pulibrary / lux

A collection of user interface components for use on Princeton University Library sites, based on Vue Design System.
MIT License
7 stars 0 forks source link

Autocomplete component breaks when label includes an apostrophe #363

Open axamei opened 3 years ago

axamei commented 3 years ago

My daughter's spring break broke the new travel request form because of the apostrophe. Allow this component to accept apostrophes.

Removed excessive items in the array:

[Vue warn]: Error compiling template:

avoid using JavaScript keyword as property name: "for"
  Raw expression: :items="[{ id: '1', label: 'Access Conference' },{ id: '1022', label: 'My daughter's spring break' },{ id: '926', label: 'ICPSR Summer Program 2020' }]" autocomplete="off"></input-autocomplete>
sdellis commented 3 years ago

This works with valid JSON containing properly escaped apostrophes. There's nothing we can do to fix invalid JSON to get the component to work, but we can use a try/catch clause (see example) to throw an error and prevent the component from breaking other components.

if(propValue) {
    try {
        a = JSON.parse(propValue);
    } catch(e) {
        alert(e); // error in the propValue
    }
}