Skip to content
This repository has been archived by the owner on Aug 16, 2021. It is now read-only.

Width detection on multiselect not working if the select is initialized before inserting into the dom. #145

Closed
Rkokie opened this issue Aug 12, 2016 · 2 comments

Comments

@Rkokie
Copy link

Rkokie commented Aug 12, 2016

In a project I am working on we're initializing the selectivity instance with some additional functionality before inserting it into the DOM, this works like a charm accept for this 1 thing.

Our input is 20px width, which is smaller than our placeholder, rendering it impossible to read.

Now I've scrambled trough the source code and found out there is this function setting the width of the input. Using a widthDetector which is used to fetch the width. This doesn't work if it's not in the DOM D:

So here my proposed solution for the function _updateInputWidth in the /inputs/multiple.js

    _updateInputWidth: function() {

        if (this.enabled) {
            var inputContent = (this.input.value ||
                                         !this._data.length && this.options.placeholder || '');
            this.input.setAttribute('size', inputContent.length + 20 + 'px';

            this.positionDropdown();
        }
    }

Using the size attribute on the input will make sure the browser always picks the right width based on the content.

@arendjr
Copy link
Owner

arendjr commented Aug 14, 2016

Thanks! Let me try this out manually, but if it works I'll definitely merge it!

@arendjr
Copy link
Owner

arendjr commented Aug 14, 2016

I changed the setAttribute line into the following:

this.input.setAttribute('size', inputContent.length + 2);

Thanks again!

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

No branches or pull requests

2 participants