Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

feat(mdRadioGroup): Radio submits on keydown/enter #990

Closed
wants to merge 2 commits into from

Conversation

marcysutton
Copy link
Contributor

With this change, mdRadioGroup will submit a form on a press of the enter key. The directive checks for a parent node with the tagName of form and if it finds a match, it will trigger a submit event.

Closes #577

@ajoslin ajoslin added the in progress Mainly for in progress PRs, but may be used for issues that require multiple PRs label Dec 19, 2014
@googlebot
Copy link

CLAs look good, thanks!

@marcysutton marcysutton added this to the 0.7.0-rc1 milestone Dec 19, 2014
@marcysutton marcysutton force-pushed the wip-radiobutton-submit branch from 27eb87f to 3bfba01 Compare December 19, 2014 03:05
keyCode: $mdConstant.KEY_CODE.ENTER
});

expect(formElement.triggerHandler).toHaveBeenCalled();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ThomasBurleson or @andrew I could use another set of eyes on this test....it's failing to spy on the form submit event even though the code works.

@marcysutton marcysutton force-pushed the wip-radiobutton-submit branch from 3bfba01 to 2802a9a Compare December 19, 2014 03:43
@marcysutton marcysutton added resolution: fixed and removed in progress Mainly for in progress PRs, but may be used for issues that require multiple PRs labels Dec 19, 2014
if (form.length > 0) {
form.triggerHandler('submit');
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think a switch is better here:

switch(ev.keyCode)
{
  case $mdConstant.KEY_CODE.LEFT_ARROW:
  case $mdConstant.KEY_CODE.UP_ARROW:

    ev.preventDefault();
    rgCtrl.selectPrevious();
    break;

  case $mdConstant.KEY_CODE.RIGHT_ARROW:
  case $mdConstant.KEY_CODE.DOWN_ARROW:

    ev.preventDefault();
    rgCtrl.selectNext();
    break;

  case $mdConstant.KEY_CODE.ENTER:

    var form = angular.element($mdUtil.getClosest(element[0], 'form'));
    if (form.length > 0) {
      form.triggerHandler('submit');
    }
    break;
}

@marcysutton marcysutton force-pushed the wip-radiobutton-submit branch from 2802a9a to ec06f68 Compare January 7, 2015 23:58
@marcysutton marcysutton force-pushed the wip-radiobutton-submit branch from ec06f68 to 8eb0097 Compare January 8, 2015 00:12
@marcysutton
Copy link
Contributor Author

Closed with 03c7592

@marcysutton marcysutton closed this Jan 8, 2015
@marcysutton marcysutton deleted the wip-radiobutton-submit branch January 8, 2015 19:20
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Focused radio buttons don't submit form on Enter
4 participants