vazco / meteor-universe-autoform-select

Meteor universe autoform select
MIT License
16 stars 10 forks source link

optionsMethod Multiselect having issue #7

Closed gatolgaj closed 8 years ago

gatolgaj commented 9 years ago

Hello, Thanks for the wonderful piece of code.

I am currently facing issue with universe-select when the data source is from google placesAPI.

First Time Selection works fine , The Second time when we search all the selected values vanishes.

Following is the helper code

selectedCities: function () {
    //    this.unblock();
        var searchText = searchValue.get();
        console.log("Search Value : "+searchValue.get());
        if (searchText) {
            var service = new google.maps.places.AutocompleteService();
            if (searchText.length > 0) {
                googleOptions = {
                    types: ['(cities)'],
                    componentRestrictions: {country: 'in'},
                    input: searchText
                };
                service.getQueryPredictions(googleOptions, function (predictions, status) {
                    if (status != google.maps.places.PlacesServiceStatus.OK) {
                        alert(status);
                        return;
                    }
                    newArray = [];
                  //  returnValues.clear();
                    for (var i = 0, prediction; prediction = predictions[i]; i++) {
                      //  returnValues.push(prediction.description);
                        //    console.log("Hello NewArray: " + prediction.description);
                        newArray.push(prediction.description);
                    }
                    // console.log("Hello NewArray: " + newArray.length);
                    /* setTimeout(function(){
                     returnValues.push('a');
                     returnValues.clear();
                     }, 200)*/

                });
            }
            //    options.values = newArray;
          //  console.log(returnValues.list());
            return returnValues.concat(newArray).list();
        }

The variable returnValues is reactive. And the Options are getting updated correctly(verified using console)

The ReactiveVar returnValues is updated using keyup event of input.

I have tried various combinations as well. Like Using the optionsMethod, Reactive Helper Method etc. etc ..

Everytime the options changes the selected values disappear.

gatolgaj commented 9 years ago

I can send a Screen cast if required.

MichalW commented 9 years ago

You have to return options with format:

return [{value: 'test1', label: 'Test 1'}, {value: 'test2', label: 'Test2'}];
gatolgaj commented 9 years ago

Hello, Sorry that was one of my initial trials but that dint work as well.

  for (var i = 0, prediction; prediction = predictions[i]; i++) {
                        returnValues.push({_id:prediction.place_id,
                                       label:prediction.description,
                                       value: prediction.description }); // set the reativeArray
                        //    console.log("Hello NewArray: " + prediction.description);
                        newArray[prediction.place_id]=prediction.description; //try setting the normal array
                    }

I have tried all the combinations with reactiveArray as well as normal array,

I have even tried to set the option using Helper and changing it dynamically using reactive VAR.

MichalW commented 9 years ago

Can you create a sample github project that I could see the whole code, test it and fix?