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

material_select does not update display value after selected option has been changed by program #1296

Closed
yangpu opened this issue May 5, 2015 · 7 comments

Comments

@yangpu
Copy link

yangpu commented May 5, 2015

I have create an angular directive to initialize select control:

  SelectDirective = function($timeout) {
    return {
      restrict: 'A',
      link: function($scope, element, attrs) {
        return $timeout(function() {
          return $(element).material_select();
        }, 50);
      }
    };
  };

to create select control in jade:

   .col.s6.input-field
      select#priority(md-select, ng-model='vm.priority')
         option(value='0') 0
         option(value='1') 1
         option(value='2') 2
         option(value='3') 3
      label(for='priority') Priority

The issue is that the select control doesn't update the display value when the priority value has been changed in controller. However, the priority value is changed according to the selected option value by mouse or key operation.

Is it possible to have a public method to select value in material_select? So that it's feasible to $watch ng-model value in directive to update the display value by the method.

@b1rdex
Copy link

b1rdex commented May 7, 2015

http://materializecss.com/forms.html

Updating/Destroying Select

If you want to update the items inside the select, just rerun the initialization code from above after editing the original select.

$(document).ready(function() {
    $('select').material_select();
  });

@yangpu
Copy link
Author

yangpu commented May 9, 2015

It looks nothing changed to re-initialize the select control after select options or value is changed.

@govindjhag
Copy link

I am facing same problem

@freddy-daniel
Copy link

Same issue in firefox we are not re-initializing.

@fega fega added the bug label Apr 4, 2017
@nesthor12
Copy link

I am also experiencing the same problem. However, I think I found a solution for this.

First set the value default option to empty string.

like this in HTML:
<select id="selectid">
<option value="">Select</option>
<option value="1">1</option>
</select>

and then in JS:
$("#selectid").find('option[value=""]').prop('selected', true);

@tomscholz
Copy link
Contributor

Duplicate of #4562

@tomscholz tomscholz marked this as a duplicate of #4562 Aug 12, 2017
@bernardoadc
Copy link

In AngularJS I solved with "track by $index"

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

No branches or pull requests

8 participants