Giter Club home page Giter Club logo

Comments (6)

hglattergotz avatar hglattergotz commented on July 2, 2024 2

@tute I wrote a custom component

import Ember from 'ember';

export default Ember.Component.extend({
  tagName: 'input',
  type: 'radio',

  attributeBindings: [
    'type',
    'name',
    'value',
    'checked',
    'selected'
  ],

  checked: Ember.computed('groupValue', 'value', function() {
    return this.get('groupValue') === this.get('value');
  }).readOnly(),

  change: function() {
    var value = this.get('value');
    var groupValue = this.get('groupValue');

    if (groupValue !== value){
      this.set('groupValue', value);
      this.sendAction('selected', this.get('name'), this.get('value'));
    }
  }
});

Template

<table class="table table-bordered table-striped">
    <thead>
    <th></th>
    <th>Yes</th>
    <th>No</th>
    <th>Don't care</th>
    </thead>
    <tbody>
    {{#each renderItems as |item|}}
        <tr>
            <td>{{item.question}}</td>
            <td>{{#radio-button value=1 name=item.id groupValue=item.answer selected="changed"}}Yes{{/radio-button}}</td>
            <td>{{#radio-button value=0 name=item.id groupValue=item.answer selected="changed"}}No{{/radio-button}}</td>
            <td>{{#radio-button value=null name=item.id groupValue=item.answer selected="changed"}}Don't care{{/radio-button}}</td>
        </tr>
    {{/each}}
    </tbody>
</table>

Controller

import Ember from 'ember';

export default Ember.Controller.extend({

  actions: {
    changed: function(name, value) {
      // handle change
    }
  },
 :

Hope it helps!

from ember-radio-button.

tute avatar tute commented on July 2, 2024 2

Added:

groupValue: Ember.computed('groupValue', function() {
  return this.get('attributeName');
}),

to the component to fix that.

from ember-radio-button.

tute avatar tute commented on July 2, 2024

@hglattergotz how did you solve this issue? I'm facing it right now, and thinking how to best solve it. Thanks!

from ember-radio-button.

tute avatar tute commented on July 2, 2024

Thank you!

from ember-radio-button.

tute avatar tute commented on July 2, 2024

@hglattergotz doesn't your this.set('groupValue', value); mutate item.answer, violating DDAU, and presenting the same bug? Thanks!

from ember-radio-button.

hglattergotz avatar hglattergotz commented on July 2, 2024

Cool, thanks!

from ember-radio-button.

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.