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

Simplified Ember.RadioButtonGroup implementation #1235

Closed
wants to merge 17 commits into from

Conversation

ghempton
Copy link
Member

@ghempton ghempton commented Aug 4, 2012

This PR contains the same API as #755 but has a simper implementation. Ember.RadioButton can also be used independently of Ember.RadioButtonGroup.

Also introduces Ember.Control which is a view that uses itself as its context, necessary for the Ember.RadioButtonGroup implementation.

@travisbot
Copy link

This pull request passes (merged 7bea55f2 into d8f76a7).

@travisbot
Copy link

This pull request passes (merged 657da83 into d8f76a7).

@caligo-mentis
Copy link
Contributor

Nice implementation! But last selected button doesn't uncheck when value becomes null.

@ghempton
Copy link
Member Author

Could you write a failing test case?

@caligo-mentis
Copy link
Contributor

Shure.

test("should uncheck previous selection when new value is null", function() {
  view = Ember.RadioButtonGroup.create({
    value: 'option1',
    name: 'testName',
    template: Ember.Handlebars.compile(
      '{{ view RadioButton value="option1" }}' +
      '{{ view RadioButton value="option2" }}'
    )
  });

  appendView();

  Ember.run(function() {
    set(view, 'value', null);
  });

  equal(get(view, 'value'), null, 'value should be set');
  equal(view.$("[value='option1']").attr('checked'), null, 'checkbox should not be checked');
  equal(view.$("[value='option2']").attr('checked'), null, 'checkbox should not be checked');
});

@ghempton
Copy link
Member Author

Thanks! Should be fixed now.

@travisbot
Copy link

This pull request passes (merged a8be921 into d8f76a7).

@caligo-mentis
Copy link
Contributor

Ok, much better. But now it's stop working in the browser at all :) I've send PR to your repo.

@caligo-mentis
Copy link
Contributor

I also realized that there is problem with 'isChecked:checked' attribute binding. At least on Chrome. I wrote the working version today, but using custom observers on isChecked property.

@travisbot
Copy link

This pull request passes (merged 9f9f58f into d8f76a7).

@ghempton
Copy link
Member Author

@caligo-mentis The test you added seems to be passing :/. I think what this really needs is a fiddle. I might have time to put one together later today.

@caligo-mentis
Copy link
Contributor

What browser you are using?
On 13.08.2012, at 20:59, Gordon L. Hempton wrote:

@caligo-mentis The test you added seems to be passing :/. I think what this really needs is a fiddle. I might have time to put one together later today.


Reply to this email directly or view it on GitHub.

@ghempton
Copy link
Member Author

I am using chrome beta. It also passed in travis (although not sure if that is working correctly)

@caligo-mentis
Copy link
Contributor

Please check this fiddle http://jsfiddle.net/ZPzU2/

The problem is what checked attribute binding does not affect on DOM element. After few changes with mouse it is not possible to update selection through bindings.

@ghempton
Copy link
Member Author

I see. I will take a pass on this today.

On Tue, Aug 14, 2012 at 12:44 PM, Andrey notifications@github.com wrote:

Please check this fiddle http://jsfiddle.net/ZPzU2/

The problem is what checked attribute binding does not affect on DOM
element. After few changes with mouse it is not possible to update
selection through bindings.


Reply to this email directly or view it on GitHubhttps://github.com//pull/1235#issuecomment-7737794.

Gordon L. Hempton
http://codebrief.com
360.460.8098

@caligo-mentis
Copy link
Contributor

Ok. And check my implementation http://jsfiddle.net/66QJm/

@ghempton
Copy link
Member Author

If your implementation passes all the tests and fixes the issue above, I say we just go with that :). Want to PR my repo?

@caligo-mentis
Copy link
Contributor

The issue is fixed, but I think the problem seems to be in attributeBindings.

I can write more tests for RadioButtonGroup, and create PR, but if problem is in ember.js we should fix it before.

On 14.08.2012, at 23:59, Gordon L. Hempton wrote:

If your implementation passes all the tests and fixes the issue above, I say we just go with that :). Want to PR my repo?


Reply to this email directly or view it on GitHub.

@wagenet
Copy link
Member

wagenet commented Oct 8, 2012

@ghempton What's the status of this?

@ahawkins
Copy link

@ghempton can you add an example of a static radio group? I mean an example where you want to display N options to the user but they don't change.

EDIT: I just noticed this. I have my RadioButtonGroup bound to a controller:

{{#view Inbox.FilterRadioButtonGroup valueBinding="selectedFilter"}}

Should setting selectedFilter change the selected radio button? If so, this does not work ATM.

EDIT2: seems it's the same thing that @caligo-mentis mentioned. The checked property is not removed properly and the UI cannot be updated via bindings.

@ahawkins
Copy link

@wagenet Status update: I've sent a PR to @ghempton repo to fix bugs. You can find it here: ghempton#2. If he does not respond in a timely fashion then I will take over this PR.

@ahawkins
Copy link

@wagenet @tomdale @wycats @kselden If there is interest in this then I can take charge and do what it takes to get this in. Otherwise close this PR if we don't want to support radio buttons in the framework.

@ghempton
Copy link
Member Author

Hey guys, sorry about not noticing this. My inbox has been swamped in github notifications. I will take a look at this today.

@ghempton
Copy link
Member Author

@twinturbo I have merged in your PR and rebased against master. Are there any other outstanding issues with this PR? @caligo-mentis?

@caligo-mentis
Copy link
Contributor

@ghempton everything should be ok now.

@wagenet
Copy link
Member

wagenet commented Nov 25, 2012

@ghempton Any idea why it doesn't merge cleanly?

@ghempton
Copy link
Member Author

@wagenet not sure... it was failing before due to a deprecated jQuery feature but I fixed the tests. Looks like Travis hasn't re-run them. Any ideas?

@wagenet
Copy link
Member

wagenet commented Nov 26, 2012

@ghempton It's not a test failure, it's that it can't merge automatically which means there's a merge conflict.

@ghempton
Copy link
Member Author

@wagenet gotcha. Just rebased again, should merge cleanly now.

@tchak
Copy link
Member

tchak commented Jun 6, 2013

Ember.Control is reserved for something else. It is supposed to be the counterpart of Ember.Route but without url.

Ember.Radio should ba a primitive not something that tries to solve all the use cases IMHO.

@ahawkins
Copy link

ahawkins commented Jun 6, 2013

@tchalk, how are they more complex than select?

On Thu, Jun 6, 2013 at 2:26 PM, Paul Chavard notifications@github.comwrote:

@ahawkins https://github.com/ahawkins the problem is radio button
semantics are quite complex. We need to expose the right primitives.


Reply to this email directly or view it on GitHubhttps://github.com//pull/1235#issuecomment-19041564
.

@stefanpenner
Copy link
Member

@ahawkins select is a minefield. Our primitive controls need some love.

@tchak
Copy link
Member

tchak commented Jun 6, 2013

@ahawkins they group... Speaking of wich, we do not support grouping of options in selects.

@ahawkins
Copy link

ahawkins commented Jun 6, 2013

tl;dr ember form elements are embarrassing.

On Thu, Jun 6, 2013 at 2:35 PM, Paul Chavard notifications@github.comwrote:

@ahawkins https://github.com/ahawkins they group... Speaking of wich,
we do not support grouping of options in selects.


Reply to this email directly or view it on GitHubhttps://github.com//pull/1235#issuecomment-19041995
.

@stefanpenner
Copy link
Member

@tchak @ahawkins confirmed. Lets

@myabc
Copy link

myabc commented Jun 8, 2013

+1 for releasing this as an ember/ember-radio-controls add-on

@stefanpenner
Copy link
Member

I think this is for the best, providing an addon with readme + tests + travis is more accessible. It would allow the project to ge the attention it needs, and reach maturity quicker.

@jagthedrummer
Copy link

+1 making this available somehow, somewhere. It's just silly that there's no way to create a radio button in Ember. It really should be a part of the core lib.

@wagenet
Copy link
Member

wagenet commented Jul 19, 2013

It looks like the vote was for an add-on. If someone releases a solid add-on we can consider whether or not it's appropriate to merge into core later.

@wagenet wagenet closed this Jul 19, 2013
@guilhermeaiolfi
Copy link

It should be in core, no matter what the API is. We can break compat later in future versions. But we need to support that out of the box. Embarrassing...

@stefanpenner
Copy link
Member

@guilhermeaiolfi are you volunteering? The providing an alternative implementation using new Ember.Component would be useful.

@wagenet
Copy link
Member

wagenet commented Aug 2, 2013

We actually can't just break the API. We're attempting to keep things stable and once we hit 1.0 (which will be soon), this becomes even more essential.

@guilhermeaiolfi
Copy link

Using Ember.Component will make it much more easy to change it's internals later. We just need to define the attrs for it.

@hlubek
Copy link

hlubek commented Aug 2, 2013

I'm using the new views from the PR without any Ember.Control and it just works (the change that was needed is merged like @wagenet noted). Would be great to make this available (at least as an add-on).


```handlebars
{{#view Ember.RadioButtonGroup name="role" valueBinding="content.role"}}
{{view RadioButton value="admin"}}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The nested view has to be accessed with {{view view.RadioButton value="..."}} in the latest RC

@denisnazarov
Copy link
Contributor

Any updates here?

@84564221
Copy link

84564221 commented Sep 5, 2013

Hello ??? Any updates here ??

@alvincrespo
Copy link
Contributor

👍 I would totally work on this, but I need to learn how to edit pull request(s).

@kumavis
Copy link
Contributor

kumavis commented Oct 31, 2013

+1

@kumavis
Copy link
Contributor

kumavis commented Oct 31, 2013

@alvincrespo the correct way would be to just create a new PR

@wagenet
Copy link
Member

wagenet commented Nov 1, 2013

If you submitted the PR, you can edit, but not if someone else did.

@mansona
Copy link
Member

mansona commented Nov 1, 2013

@wagenet @alvincrespo I know you can checkout the pull request and then you could effectively "fork" the pull request and make a new one. Once you do then if you mention the new pull request here it will become "linked"
(hope I helped ;)

@chainlink
Copy link

+1 for this feature.

@namlook
Copy link

namlook commented Jan 30, 2014

Any update about this feature ?

@ckornell
Copy link

ckornell commented Feb 5, 2014

I pulled this code from @ghempton and updated it to extend from component, fixed up the documentation, updated the tests, and added helpers. It works great aside from the one failing test that I can't seem to hammer out; although, I see it working when I build Ember and use it in production, so I think I'm just missing something really simple.

Can someone please help me pass the last test so I can re-submit this PR? This is my first attempt at working with the Ember source and the Ember Testing Suite.

I really believe this should be in the core and @ghempton did an excellent job with it; I would love to help out in any way I can to make it happen.

Here's my branch: https://github.com/cmkornell/ember.js/tree/radio-button-group
The failing test: Ember.RadioButtonGroup: value should update correctly after change event

@mansona
Copy link
Member

mansona commented Sep 4, 2014

I posted this on #4352 but i wanted to get some feedback on it and continue the discussion: https://www.npmjs.org/package/ember-radio-buttons Its a slightly simpler implementation than @ghempton 's but I think it should do for most cases

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.