Giter VIP home page Giter VIP logo

Comments (7)

millenjo avatar millenjo commented on August 24, 2024

I am still having issues with this, setting an empty array as options and populating it later on renders nothing. I removed the if check for "config.create" in the addSelectizeOptions function around line 64-66 and that solved it. It only seemed to work with create: true because otherwise it wouldn't add the options to selectize. Whats the reason for this create: true check?

from angular-selectize.

machineboy2045 avatar machineboy2045 commented on August 24, 2024

You've found a bug, good sir. :) That if statement should be removed. If you make a pull request I'll merge it. Thanks for finding this.

from angular-selectize.

UmarFarouk avatar UmarFarouk commented on August 24, 2024

Loading data via ajax is still not working for me

I have the following:

<div id="province" selectize="provinceConfig" options='provinces' ng-model="province"></div>
And
    // Create variables
    $scope.province = null;
    $scope.provinces = [];

    // Create config
    $scope.provinceConfig = {
        maxItems: 1,
        placeholder: 'Select a Province'
    };

    // load provinces 
    $http({
        method: 'GET',
        url: HostnameFactory.url + '/register/provinces'
    }).success(function(data){
        // Add items to province array
        $.each(data, function (index, item) {
            $scope.provinces.push(item.name);
        });
    }).error(function(data){
        showAlert("Error!", data.text, 'danger');
    });
Even if I set
    $scope.provinceConfig = {
        create: true,
        maxItems: 1,
        placeholder: 'Select a Province'
    };
I also tried
    $scope.provinceConfig = {
        create: true,
        preload: true,
        maxItems: 1,
        placeholder: 'Select a Province'
    };
If the array values are hard coded, it works fine.
Am I doing something wrong?

from angular-selectize.

machineboy2045 avatar machineboy2045 commented on August 24, 2024

Can you replicate this by editing the example Plunkr on the Readme page? It uses a timeout to simulate loading options via AJAX.

from angular-selectize.

UmarFarouk avatar UmarFarouk commented on August 24, 2024

See Plunker.

If I insert strings into myOptions array in the $timeout function, it does not load:

  $timeout(function(){
    for(var i = 0; i < 20; i++){
      $scope.myOptions.push('value'+i)
    }
  }, 500)

However, if i initialise myOptions with the string values, it loads fine:

  $scope.myOptions = ['abc', 'def'];
  //$timeout(function(){
  //  for(var i = 0; i < 20; i++){
  //    $scope.myOptions.push('value'+i)
  //  }
  //}, 500)

It seems like when you are loading the data via an api, myOptions needs to be an array of objects as opposed to it just being an array of strings.

I think I might be able to get it to work with an array of strings, if so, i will let you know.
Thanks for quite a nifty directive!

from angular-selectize.

UmarFarouk avatar UmarFarouk commented on August 24, 2024

I have created a Pull Request.
Not sure if thats the correct solution, you can decide.

from angular-selectize.

machineboy2045 avatar machineboy2045 commented on August 24, 2024

I want to support this. But like yourself I'm not yet sure the best way to do it. I'll read over your commit some more.

from angular-selectize.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.