Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
  <head>
    <!-- Twitter bootstrap -->
    <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet">
    <!-- apiCheck is used by formly to validate its api -->
    <script src="//rawgit.com/kentcdodds/apiCheck.js/master/dist/api-check.min.js"></script>
    <!-- This is the latest version of angular (at the time this template was created) -->
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
  
    <!-- This is the current state of master for formly core. -->
    <script src="https://rawgit.com/formly-js/angular-formly/master/dist/formly.js"></script>
    <!-- This is the current state of master for the bootstrap templates -->
    <script src="//rawgit.com/formly-js/angular-formly-templates-bootstrap/master/dist/angular-formly-templates-bootstrap.js"></script>
    
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/0.13.0/ui-bootstrap-tpls.min.js"></script>
  <!-- ui-select files -->
  <script src="https://rawgit.com/angular-ui/ui-select/master/dist/select.js"></script>
  <link rel="stylesheet" href="https://rawgit.com/angular-ui/ui-select/master/dist/select.css">
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular-sanitize.js"></script>
    
  <!-- Select2 theme -->
  <link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/select2/3.4.5/select2.css">
  <!--
    Selectize theme
    Less versions are available at https://github.com/brianreavis/selectize.js/tree/master/dist/less
  -->
  <link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/selectize.js/0.8.5/css/selectize.default.css">
  <!-- <link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/selectize.js/0.8.5/css/selectize.bootstrap2.css"> -->
  <!-- <link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/selectize.js/0.8.5/css/selectize.bootstrap3.css"> -->
    
    <title>Angular Formly UI Select Issue</title>
  </head>
  <body ng-app="formlyExample" ng-controller="MainCtrl as vm">
    <div>
      <h1>angular-formly example: {{vm.exampleTitle}}</h1>
      <div>
         Issue with ui-select and Formly
      </div>
      
      <div>
        <h2>Steps to Reproduce</h2>
        <ol>
          <li>
             Type into address filter which sets the model for ui-select.  UI-Select filters properly
          </li>
          <li>
            Type into Address which should update $viewValue and fire $http request.  This does not work.  $select.search is updated with typed in value but expressionProperties does not fire the vm.refresAddress($viewValue)
          </li>
          <li>
            
          </li>
        </ol>
      </div>
      
      <hr />
      <form ng-submit="vm.onSubmit()" name="vm.form" novalidate>
        <formly-form model="vm.model" fields="vm.fields" options="vm.options">
          <button type="submit" class="btn btn-primary submit-button" ng-disabled="vm.form.$invalid">Submit</button>
          <button type="button" class="btn btn-default" ng-click="vm.options.resetModel()">Reset</button>
        </formly-form>
      </form>
      <hr />
      <h2>Model Value</h2>
      <pre>{{vm.model | json}}</pre>
      <h2>Fields <small>(note, functions are not shown)</small></h2>
      <pre>{{vm.originalFields | json}}</pre>
      <h2>Form</h2>
      <pre>{{vm.form | json}}</pre>
    </div>
    <div style="margin-top:30px">
      <small>
        This is an example for the
        <a href="https://formly-js.github.io/angular-formly">angular-formly</a>
        project made with ♥ by
        <strong>
          <span ng-if="!vm.author.name || !vm.author.url">
            {{vm.author.name || 'anonymous'}}
          </span>
          <a ng-if="vm.author.url" ng-href="{{::vm.author.url}}">
            {{vm.author.name}}
          </a>
        </strong>
        <br />
        This example is running angular version "{{vm.env.angularVersion}}" and formly version "{{vm.env.formlyVersion}}"
      </small>
    </div>
    <!-- Put custom templates here -->
  </body>
</html>
 
body {
  margin: 20px
}
.formly-field {
  margin-bottom: 16px;
}
 
/* global angular */
(function() {
  
  'use strict';
  var app = angular.module('formlyExample', ['formly', 'formlyBootstrap', 'ui.bootstrap', 'ngSanitize', 'ui.select']);
  
  app.run(function(formlyConfig) {
    formlyConfig.setType({
      name: 'ui-select',
      extends: 'select',
      template: '<ui-select ng-model="model[options.key]" theme="bootstrap" ng-required="{{to.required}}" ng-disabled="{{to.disabled}}" reset-search-input="false"> <ui-select-match placeholder="{{to.placeholder}}"> {{$select.selected[to.labelProp || \'name\']}} </ui-select-match> <ui-select-choices group-by="to.groupBy" repeat="option[to.valueProp || \'value\'] as option in to.options | filter: $select.search"> <div ng-bind-html="option[to.labelProp || \'name\'] | highlight: $select.search"></div> </ui-select-choices> </ui-select>'
    });
    
    formlyConfig.setType({
      name: 'ui-select-select2',
      extends: 'ui-select',
      template: '<ui-select ng-model="model[options.key]" theme="select2" ng-required="{{to.required}}" ng-disabled="{{to.disabled}}" reset-search-input="false"> <ui-select-match placeholder="{{to.placeholder}}"> {{$select.selected[to.labelProp || \'name\']}} </ui-select-match> <ui-select-choices group-by="to.groupBy" repeat="option[to.valueProp || \'value\'] as option in to.options | filter: $select.search"> <div ng-bind-html="option[to.labelProp || \'name\'] | highlight: $select.search"></div> </ui-select-choices> </ui-select>'
    });
    
    formlyConfig.setType({
      name: 'ui-select-selectize',
      extends: 'ui-select',
      template: '<ui-select ng-model="model[options.key]" theme="selectize" ng-required="{{to.required}}" ng-disabled="{{to.disabled}}" reset-search-input="false"> <ui-select-match placeholder="{{to.placeholder}}"> {{$select.selected[to.labelProp || \'name\']}} </ui-select-match> <ui-select-choices group-by="to.groupBy" repeat="option[to.valueProp || \'value\'] as option in to.options | filter: $select.search"> <div ng-bind-html="option[to.labelProp || \'name\'] | highlight: $select.search"></div> </ui-select-choices> </ui-select>'
    });
  });
  
  app.controller('MainCtrl', function MainCtrl(formlyVersion,$http) {
    var vm = this;
    // funcation assignment
    vm.onSubmit = onSubmit;
    // variable assignment
    vm.author = { // optionally fill in your info below :-)
      name: 'Benjamin Orozco',
      url: 'https://github.com/benoror'
    };
    vm.exampleTitle = 'UI Select'; // add this
    vm.env = {
      angularVersion: angular.version.full,
      formlyVersion: formlyVersion
    };
    
    vm.refreshAddresses = function(address) {
      var params = {address: address, sensor: false};
      return $http.get(
        'http://maps.googleapis.com/maps/api/geocode/json',
        {params: params}
      ).then(function(response) {
        return response.data.results;
      });
    };
    
    
    vm.model = {state:'AZ'};
    vm.options = {};
   
    
    vm.fields = [
      {
        key: 'addressfilter',
        type: 'input',
        templateOptions: {
          type : 'text',
          label: 'Address Filter (working)',
          "onKeypress": "model.formatted_address = fc.$viewValue"
        }
      },
      {
        key: 'formatted_address',
        type: 'ui-select',
        templateOptions: {
          label: 'Address',
          valueProp: 'formatted_address',
          labelProp: 'formatted_address',
          options: []
        },
          expressionProperties: {
            'templateOptions.options': function ($viewValue, $modelValue, scope)
            {
              console.log($viewValue);
              console.log($modelValue);
              return vm.refreshAddresses($viewValue);
            }
          }
      },
    ];
    
    vm.originalFields = angular.copy(vm.fields);
    
    // function definition
    function onSubmit() {
      vm.options.updateInitialValue();
      alert(JSON.stringify(vm.model), null, 2);
    }
  });
})();
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers