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

Select does not update, when your change it from JS #466

Closed
Saiberbest opened this issue Jan 15, 2015 · 3 comments
Closed

Select does not update, when your change it from JS #466

Saiberbest opened this issue Jan 15, 2015 · 3 comments

Comments

@Saiberbest
Copy link

I do some changes in this function:

$.fn.material_select = function () {
      $(this).each(function(){
        $select = $(this);
        if ( $select.hasClass('browser-default') || $select.hasClass('initialized')) {
          var span = $select.parent().children('span');
          var uniqueID = span.attr('data-activates');
          var options = $('#' + uniqueID);
          options.empty();
          //return; // Continue to next (return false breaks out of entire loop)
        }else{
         var uniqueID = 'select-options-'+guid();
         var options = $('<ul id="' + uniqueID+'" class="dropdown-content select-dropdown"></ul>');
         var wrapper = $('<div class="select-wrapper"></div>');
        }


        var selectOptions = $select.children('option');
        if ($select.find('option:selected') !== undefined) {
          var label = $select.find('option:selected');
        }
        else {
          var label = options.first();
        }


        // Create Dropdown structure
        selectOptions.each(function () {
          // Add disabled attr if disabled
          options.append($('<li class="' + (($(this).is(':disabled')) ? 'disabled' : '') + '"><span>' + $(this).html() + '</span></li>'));
        });


        options.find('li').each(function (i) {
          var $curr_select = $select;
          $(this).click(function () {
            // Check if option element is disabled
            if (!$(this).hasClass('disabled')) {
              $curr_select.find('option').eq(i).prop('selected', true);
              // Trigger onchange() event
              if (typeof($curr_select.context.onchange) === "function") {
                $curr_select[0].onchange();
              }
              $curr_select.prev('span.select-dropdown').html($(this).text());
            }
          });

        });
        if ( $select.hasClass('browser-default') || $select.hasClass('initialized')) {
          span.html(label.html());
        }else{
          // Wrap Elements
          $select.wrap(wrapper);
          // Add Select Display Element
          var $newSelect = $('<span class="select-dropdown ' + (($select.is(':disabled')) ? 'disabled' : '')
                           + '" data-activates="' + uniqueID +'">' + label.html() + '</span>');
          $select.before($newSelect);
          $('body').append(options);
          // Check if section element is disabled
          if (!$select.is(':disabled')) {
            $newSelect.dropdown({"hover": false});
          }
          $select.addClass('initialized');
        }      

      });
    };
@svartalf
Copy link

Maybe you should create pull request for it? At least diff with highlighted changes will be more useful ;)

@carlosperate
Copy link

This seems to be relevant to issue #452
A pull request would definitely be appreciated.

@Dogfalo
Copy link
Owner

Dogfalo commented Jan 23, 2015

duplicate of #452

@Dogfalo Dogfalo closed this as completed Jan 23, 2015
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

4 participants