eakoriakin / ionic-selectable

Ionic Selectable is an Ionic versatile and highly customizable component that serves as a replacement to Ionic Select, and allows to search items, including async search, create items, customize the layout with templates and much more. It provides an intuitive API and is easy to set up and use.
MIT License
549 stars 125 forks source link

Unable to use with just strings as value #394

Closed pwilkowski closed 1 year ago

pwilkowski commented 2 years ago

Hello, I do have some weird issue when i try to use strings as value, i get plenty of errors like this:

index-463d92b6.js:1664 

       SyntaxError: Unexpected token 'U', "UNKNOWN_OR"... is not valid JSON
    at JSON.parse (<anonymous>)
    at IonicSelectableComponent.setValue (ionic-selectable_2.entry.js:1008:48)
    at IonicSelectableComponent.componentWillLoad (ionic-selectable_2.entry.js:560:10)
    at safeCall (index-463d92b6.js:1234:20)
    at dispatchHooks (index-463d92b6.js:1095:23)
    at Array.dispatch (index-463d92b6.js:1079:28)
    at consume (index-463d92b6.js:1704:13)
    at flush (index-463d92b6.js:1719:9) undefined

Error appears here:

 setValue(value, isChangeInternal = true) {
    var _a;
    this.isChangeInternal = isChangeInternal;
    if (value) {
      // If type is string convert to object
      value = typeof value === 'string' ? JSON.parse(value.replace(/\'/gi, '"')) : value; // HERE
      const isArray = Array.isArray(value);
      if (!isArray) {
        value = [value];
      }

Unfortunately setting [shouldStoreItemValue]="true"

did not fix it.

Is it possible to use ONLY strings as values while passing whole objects with properties?

edy-ap commented 2 years ago

Hi what version are you using?