Giter Club home page Giter Club logo

Comments (7)

cowboyd avatar cowboyd commented on July 28, 2024

With emberx-select, the only way that Active would be checked would be if model.status had a value of 1. Are you suggesting that {{x-select}} should initialize model.status to the first value if it is undefined?

from emberx-select.

alexphys avatar alexphys commented on July 28, 2024

I think that {{x-select}} should set model.status to the first value not only when it is rendered but also in cases the content of select options changes and the selected value is no longer included in the options.

Imagine a case where you have 2 selects where the second select's options are dependent on the selection of the first select;

###First selection 

{{#x-select value=model.parent }}
  {{#each option in array}}
    {{#x-option value=option}}option.name{{/x-option}}
  {{/each}}
{{/x-select}}

###2nd selection with options dependent on the 1st selection

{{#x-select value=model.child }}
  {{#each option in model.parent.children}}
    {{#x-option value=option}}option.name{{/x-option}}
  {{/each}}
{{/x-select}}

from emberx-select.

matthewnessworthy avatar matthewnessworthy commented on July 28, 2024

I agree with @alexphys , and in general, since this is a select helper/native replacement, it should function in the same way, which means preselecting the initial value as well as selecting the first value in the list should the selected value be removed at a later time

from emberx-select.

sa4breeze avatar sa4breeze commented on July 28, 2024

The default selected attribute in x-option also has an issue.

Snippet 1:

{{#x-select class="form-control" value=SomePerson}}
    {{#x-option value=0 selected}}Alice{{/x-option}}
    {{#x-option value=1}}Bob{{/x-option}}
{{/x-select}}

should work similarly to the one shown below:

Snippet 2:

<select id=SomePerson>
    <option value=0 selected>Alice</option>
    <option value=1>Bob</option>
</select>

In snippet 1, using x-select to pass the value for SomePerson results in undefined. That shouldn't be the case.

It should pass the value as 0 which is set to selected as shown in Snippet 2.

from emberx-select.

maksimluzik avatar maksimluzik commented on July 28, 2024

When this will be fixed? I think this is really a major issue/bug affecting basic functionality of the addon

from emberx-select.

lydiaguarino avatar lydiaguarino commented on July 28, 2024

Hello there
I am currently working on a solution for these issues.

I understand there to be three requests:

  1. Fix the broken selected=true behavior for specifying a default selection
  2. Provide a way to default to the first option in the list on render
  3. Provide a way to default to the first option in the list when the selection is no longer valid because the options in the list have changed

For the time being, we can offer the following solution:

{{#x-select value=model.status }}
  {{#x-option value=1}}Active{{/x-option}}
  {{#x-option value=2 selected=true}}Inactive{{/x-option}}
{{/x-select}}

Will result in model.status defaulting to value=2 Inactive if model.status is not already set.

{{#x-select value=model.status }}
  {{#each choices as | choice index |}}
    {{#if index}}
      {{#x-option value=choice.value}}{{choice.name}}{{/x-option}}
    {{else}}
      {{#x-option value=choice.value selected=true}}{{choice.name}}{{/x-option}}
    {{/if}}
  {{/each}}
{{/x-select}}

Will result in model.status defaulting to the first option in the list if model.status is not already set. This will also update correctly if the content of choices changes.

Would this solution satisfy your use cases until we can implement a more elegant solution?

from emberx-select.

lydiaguarino avatar lydiaguarino commented on July 28, 2024

This was addressed in #90 to be released in 2.1

from emberx-select.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.