Select2 triggering event don’t loading additional data
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 25.9k
- Forks
- 6.1k
- Avg merge
- 8d 53m
- Merged PRs (30d)
- 4
Description
I’m trying to load some important data on my select (select2) that will be used in other parts of the page in the future, but the Triggering Event is not loading the additional data. The code and results are shown below. If anyone has any suggestions, I’d be grateful.
$('#id_cc1').select2();
var data = {
id: 1,
text: 'text_default',
text2: 'text_2',
text3: 'text_3'
};
var newOption = new Option(data.text, data.id, true, true);
$('#id_cc1').append(newOption).trigger('change'); //until this point, everything works
$('#id_cc1').trigger({
type: 'select2:select',
params: {
data: data
}
});
console.log($('#id_cc1').select2('data')[0]['text']);// return text_default
console.log($('#id_cc1').select2('data')[0]['text2']);// return undefined
I believe the second ‘console.log’ should return: ‘text_2’.
Contributor guide
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 with the provided JavaScript/jQuery reproduction, including the Select2 initialization, appended option, and manually triggered select2:select event. Reproduce the two select2('data') lookups and trace whether the additional text2 and text3 fields are retained; done when the reported data is returned consistently or the expected behavior is clarified.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, jquery
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100