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

selected option not working on Chrome #53

Open
rcstr opened this issue Sep 8, 2014 · 2 comments
Open

selected option not working on Chrome #53

rcstr opened this issue Sep 8, 2014 · 2 comments

Comments

@rcstr
Copy link

rcstr commented Sep 8, 2014

URL: http://jsfiddle.net/T6Vxw/

i been fighting with this for a few days, for some reason this happen only on chrome
anybody has a clue on this? or has resolved this?

thank you!

@tadeck
Copy link

tadeck commented Sep 8, 2014

This issue is very ambiguous. I suppose author wanted to say that selecting option in his dropdown does not result in what he expected. But what happens after it is selected, is clearly breaking the widget.

@rommelxcastro, this plugin works by replacing original control with some nicely styled bunch of HTML tags that have nothing to do with <select> or <option>. This code, however:

$("#first").minimalect({
    onchange: function(value, text){
        if(value == "yes"){
            var html = "";
            $.each(makes, function(k,v){
                html += '<option value="'+v+'">'+v+'</option>';
            });
            $("#second").html(html);
        }
    }
});

$("#second").minimalect({
    placeholder: "Make"
});

is replacing this nicely generated HTML with <option> tags. This is not a way to go.

One way to do it, is to generate or initialize second dropdown on the fly (you need to add style="display: none;" to the <select> tag):

$("#first").minimalect({
    onchange: function(value, text){
        if(value == "yes"){
            var html = "";
            $.each(makes, function(k,v){
                html += '<option value="'+v+'">'+v+'</option>';
            });
            $("#second").html(html);
        }

        $("#second").show(0);
        $("#second").minimalect({
            placeholder: "Make"
        });
    }
});

The other option is to take a look at what HTML is used in final outlook of the widget, then use it instead of <option> tags.

@patrickgalbraith
Copy link
Contributor

@rommelxcastro This is due to the live option.

Basically in modern browsers minimalect detects changes to the dom and updates the select automatically. But it can cause issues in some cases.

See this fiddle http://jsfiddle.net/6qe1zssg/1/ for working example.

Note since live is disabled you will need to manually call $("#second").minimalect('update');.

Also I set searchable: false to make it more like a standard dropdown. You can re-enable it if you want.

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

3 participants