selectivity icon indicating copy to clipboard operation
selectivity copied to clipboard

jquery placeholder not working when init was done on a select tag

Open AndorLundgren opened this issue 8 years ago • 5 comments

Have tested with/without placeholder on select, with/without placeholder as parameter and on single and multi selects. When init on select tag is used first option is selected not the placeholder parameter or the data-placeholder attribute value.

<select class="placeholder" data-placeholder="my-placeholder-text">
    <option value="x">X</option>
    <option value="y">Y</option>
</select>
<script>
    $(function () {
        $('.placeholder').selectivity({
            placeholder: "tex"
         });
     });
</script>

On divs it works.

AndorLundgren avatar Nov 11 '16 12:11 AndorLundgren

This issue I cannot reproduce... I've just written a test case for this, but it passed straight away. Also the demo page doesn't show this problem.

Maybe I'm misunderstanding the problem, but are you sure the first option in your example doesn't have the "selected" attribute? Based on your previous issue report, I can assume you're using version 3, right?

arendjr avatar Nov 18 '16 12:11 arendjr

Sorry for not making my issue message clear enough. Yes I am using the version 3. I am using a select not a div to init on. I use the jquery version. Placeholder does not work. Please see jsfiddle where I use the demo page selectivty version.

It do work if you init on a div with items as on your demo page.

AndorLundgren avatar Nov 20 '16 08:11 AndorLundgren

Thanks for the fiddle, at least I can reproduce it now :)

Still a bit baffled why it fails there, but didn't with my other test... will keep you posted!

arendjr avatar Nov 21 '16 09:11 arendjr

Can confirm I cannot get placeholder to work using Zepto. I'm using allowClear: true also but it's still initialising with the first option selected and I only see the placeholder when clearing the input manually.

alexcroox avatar Dec 06 '16 08:12 alexcroox

A temporary workaround to get the placeholder to show is

$('.select--dynamic').selectivity({
    allowClear: true
});

setTimeout(function() {
     $('.select--dynamic').selectivity('clear');
}, 500);

Although this does trigger an error it works

vendor.min.js:4 Uncaught TypeError: Cannot read property 'value' of undefined(…)
(anonymous function) @ vendor.min.js:4
i.proxy @ vendor.min.js:1triggerEvent @ vendor.min.js:4
triggerChange @ vendor.min.js:4
setData @ vendor.min.js:4
clear @ vendor.min.js:4
(anonymous function) @ vendor.min.js:3
(anonymous function) @ vendor.min.js:1each @ vendor.min.js:1r.fn.selectivity @ vendor.min.js:3
(anonymous function) @ bundle.js:631

alexcroox avatar Dec 06 '16 09:12 alexcroox