Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation for default items appears to be invalid #52

Open
rthomps7 opened this issue Jun 12, 2019 · 11 comments
Open

Documentation for default items appears to be invalid #52

rthomps7 opened this issue Jun 12, 2019 · 11 comments

Comments

@rthomps7
Copy link

I was having trouble with defaultItems crashing my app, and found out the docs seem wrong?

Docs here show this:

var config = {
    title: "Select something",
    items:[
        [data.numbers],
        [data.fruits]
    ],
    defaultItems: [
        //the number '2'
        {index:0, value: data.numbers[2]},

        //the value 'Pear'
        {index:1, value: data.fruits[2]}
    ]
};

But I couldn't get it working until I tried this:

var config = {
    title: "Select something",
    items:[
        [data.numbers],
        [data.fruits]
    ],
    defaultItems: {
      0: data.numbers[2].description,
      1: data.fruits[2].description,
    } 
};

Am I missing something? I'll roll with what's working now, but I'm concerned something else is awry.

@jasonmamy
Copy link
Owner

jasonmamy commented Jun 20, 2019 via email

@rthomps7
Copy link
Author

My info is below, but it's pretty unrelated ionic for me. I'm not using anything ionic related to invoke cordova-wheel-selector-plugin. I'm just installing with cordova and then trying to run window.SelectorCordovaPlugin.showSelector.

Ionic:

   ionic (Ionic CLI)  : 4.5.0 
   Ionic Framework    : ionic-angular 3.9.2
   @ionic/app-scripts : 3.2.2

Cordova:

   cordova (Cordova CLI) : 8.1.2 ([email protected])
   Cordova Platforms     : ios 4.5.5
   Cordova Plugins       : cordova-plugin-ionic 5.3.0, cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 4.0.1, (and 32 other plugins)

System:

   Android SDK Tools : 26.1.1 
   ios-sim           : 7.0.0
   NodeJS            : v8.12.0
   npm               : 6.9.0
   OS                : macOS Mojave
   Xcode             : Xcode 10.2.1 Build version 10E1001

@davidquon
Copy link

I'm having issues with setting the default value as well using Ionic for Android. Here's my ionic info.

Ionic:

   Ionic CLI                     : 6.10.0 (/Users/DQ/.nvm/versions/node/v10.20.0/lib/node_modules/@ionic/cli)
   Ionic Framework               : @ionic/angular 5.0.7
   @angular-devkit/build-angular : 0.803.26
   @angular-devkit/schematics    : 8.3.26
   @angular/cli                  : 8.3.26
   @ionic/angular-toolkit        : 2.2.0

Cordova:

   Cordova CLI       : 9.0.0 ([email protected])
   Cordova Platforms : android 8.1.0
   Cordova Plugins   : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 4.2.0, (and 17 other plugins)

Utility:

   cordova-res : not installed
   native-run  : 1.0.0

System:

   Android SDK Tools : 26.1.1 (/Users/DQ/Library/Android/sdk)
   NodeJS            : v10.20.0 (/Users/DQ/.nvm/versions/node/v10.20.0/bin/node)
   npm               : 6.14.5
   OS                : macOS Catalina
   Xcode             : Xcode 11.5 Build version 11E608c

I've tried to use the way the docs show:

    defaultItems: [
        //the number '2'
        {index:0, value: data.numbers[2]},
    ]

And the way it seems to works for others:

    defaultItems: {
      0: data.numbers[2].description,
    } 

The caveat is for me I only have 1 item in my item list instead of 2. If anyone has any suggestions please let me know.

@jasonmamy
Copy link
Owner

jasonmamy commented Jun 10, 2020 via email

@davidquon
Copy link

So I tried these without it working with items: [entries, entries],:

defaultItems: { "0": item.displayValue, "1": item.displayValue },
defaultItems: [{ "0": item.displayValue , "1": item.displayValue }],
defaultItems: [{ "0": item.displayValue }, { "1": item.displayValue }],

Then I tried this and it worked:

items: [entries, entries],
defaultItems: [
  { index: 0, value: item.displayValue },
  { index: 1, value: item.displayValue }
],

And then I tried this and it worked:

items: [entries],
defaultItems: [
  { index: 0, value: item.displayValue }
],

So the tldr; is that it seems that the documented way of setting defaultItems for Ionic works as specified in the documentation. Not sure why it didn't work for me the other day though as I'm nearly 💯 I tried this. ¯_(ツ)_/¯
https://ionicframework.com/docs/native/wheel-selector

Thanks for the great plugin @jasonmamy and support. 👏🍻

@jasonmamy
Copy link
Owner

jasonmamy commented Jun 11, 2020 via email

@davidquon
Copy link

Correct. I can confirm with these versions:

"cordova-wheel-selector-plugin": "^1.1.7",
"@ionic-native/wheel-selector": "^5.26.0",

using Ionic version 6.10.0 and Cordova version 9.0.0 the documentation here https://ionicframework.com/docs/native/wheel-selector works as expected with regards to defaultItems.

     defaultItems: [
       {index:0, value: this.jsonData.numbers[2].description},
       {index: 1, value: this.jsonData.fruits[3].description}
     ]

Thanks for the support @jasonmamy. 👍

@edmondchui
Copy link

I also have the same issue reported at the beginning of this issue. I'm using version 1.1.7 of this plugin on iOS.

After debugging into the Objective-C code, I found that in this segment https://github.com/jasonmamy/cordova-wheel-selector-plugin/blob/1.1.7/src/ios/SelectorCordovaPlugin.m#L50-L58

    if (defaultItems) {
      NSString *value = [defaultItems objectForKey:columnIndexString];
      NSUInteger index = [[_items objectAtIndex:columnIndex] indexOfObject:value];
      if (NSNotFound != index) {
        initialValueIndex = index;
      }
    }
    [_itemsSelectedIndexes setValue:@(initialValueIndex) forKey:columnIndexString];
    [_pickerView selectRow:initialValueIndex inComponent:columnIndex animated:NO];

defaultItems should be an NSDictionary (Hash), not an array. So I have to set defaultItems in Javascript this way to make it work:

     defaultItems: [
       '0': this.jsonData.numbers[2].description},
       '1': value: this.jsonData.fruits[3].description}
     ]

@edmondchui
Copy link

On Android, using the same code, I can only get the second item showing the default value correctly. I tried to debug into the Java code but can't seem to find anything helpful.

When I revert to the documented way to set defaultItems on Android, I can't get any of the default values show up.

@mirko77
Copy link

mirko77 commented Jul 5, 2022

@edmondchui I have the same issue, did you figure it out on Android?

@mirko77
Copy link

mirko77 commented Jul 5, 2022

I can confirm the only way to make it work on Android is to provide a JSON object, not an array of objects.


defaultItems: {
0: data.numbers[2].description,
1: data.fruits[2].description
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants