lcdsantos / lcdsantos/jQuery-Selectric
Add dynamically default values by option
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:

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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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