Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Help] Cant Set Selected Value For Multiple Select with Other Initialization Paramaters #1470

Closed
cupcakedream opened this issue May 16, 2020 · 3 comments
Assignees
Labels
type/bug Any issue which is a bug or PR which fixes a bug type/usage Any support issues asking for help
Milestone

Comments

@cupcakedream
Copy link

Hey All -

I'm trying to set selected values for a multiple select dropdown but I can't seem to figure out how to do this during initialization. I know I can do it after initialize but I want to avoid firing an onchange event at all costs. I've looked everywhere can't seem to figure out how to do this. Is it not supported?

    jQuery('.outcome select').dropdown({
        selected : [1,2,3,4,5],
        onChange : function( x,y,z ) {
            jQuery.ajax({ url : 'ajax.php', method : 'post',
                data : { action : 'outcome', id : y }
            });
        }
    });
@cupcakedream cupcakedream added state/awaiting-triage Any issues or pull requests which haven't yet been triaged type/usage Any support issues asking for help labels May 16, 2020
@lubber-de
Copy link
Member

lubber-de commented May 16, 2020

I think you found a bug.
You can already provide preselected values during initialization:

  1. By converting a select tag and having the desired option values of that original select having the selected attribute
<select class="ui dropdown" multiple="">
  <option value="">State</option>
  <option selected value="1">one</option>
  <option value="2">two</option>
  <option selected value="3">three</option>
</select>
  1. By providing the selected attribute to the desired fields of the given values setting
$('.ui.dropdown').dropdown({
  values:[{
    value:1,
    name: 'one',
    selected: true
  },{
    value:2,
    name: 'two'
  },{
    value:3,
    name: 'three',
    selected: true
  }]
});

Both options will define the preselected values without the need of an additional set selected behavior call after initialization.
However, (and this is why i will tag this as a bug) using the values setting will call the onChange event for each selected value, which should be fetched because we already have a fireOnInit setting, which should prevent this

When using option 1 (converting a select) you are ready to go: The previous selected values are preselected without triggering the onChange callback

For option 2 i will prepare a PR to fix this

See
https://jsfiddle.net/7g2ywtfc/

@lubber-de lubber-de self-assigned this May 16, 2020
@lubber-de lubber-de added type/bug Any issue which is a bug or PR which fixes a bug and removed state/awaiting-triage Any issues or pull requests which haven't yet been triaged labels May 16, 2020
@lubber-de lubber-de added this to the 2.8.x milestone May 16, 2020
@lubber-de
Copy link
Member

Fixed it by #1471
See https://jsfiddle.net/7g2ywtfc/1/

@cupcakedream
Copy link
Author

Awesome thanks!

@lubber-de lubber-de added tag/next-release/nightly Any issue which has a corresponding PR which has been merged and is available in the nightly build and removed state/has-pr An issue which has a related PR open labels May 20, 2020
@lubber-de lubber-de removed the tag/next-release/nightly Any issue which has a corresponding PR which has been merged and is available in the nightly build label Jun 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug Any issue which is a bug or PR which fixes a bug type/usage Any support issues asking for help
Projects
None yet
Development

No branches or pull requests

2 participants