lcdsantos / lcdsantos/jQuery-Selectric

Add dynamically default values by option

Open
#233 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
715
Forks
149
PR merge metrics
No merged PRs in 30d

Description

Hello, I modified the plugin locally to fit my needs. Instead of writing every option directly inside the HTML like this :

<select>
    <option>Option 1</option>
    <option>Option 2</option>
    <option>Option 3</option>
</select>

I added an option like that :

$('select').selectric({
    ...
    defaultOptions: ['Option 1', 'Option 2', 'Option 3']
});

To get this result:
image

If you guys think it could be a good idea to add this feature to Selectric, there is the code to add after the line 408:

if (typeof _this.options.defaultOptions === "object" && _this.options.defaultOptions) {
    var defaultOptions = [..._this.options.defaultOptions].map(function (value) {
        var newOption = document.createElement('option');
        newOption.innerText = value;

        return newOption;
    });

    $options = $([...$options, ...defaultOptions]);
}

It uses ES6 syntaxes so you make sure you'll support it.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in the code after line 408, where the issue proposes adding dynamically generated options from a defaultOptions setting. Check how Selectric currently builds its option collection and verify the behavior with a select initialized through the jQuery plugin; done means the supplied values appear as options without requiring them in the original HTML.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, jquery
Domain
frontend
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.