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

Is there a way to make a table form submit on enter? #743

Open
amfsyn opened this issue Dec 20, 2018 · 5 comments
Open

Is there a way to make a table form submit on enter? #743

amfsyn opened this issue Dec 20, 2018 · 5 comments

Comments

@amfsyn
Copy link

amfsyn commented Dec 20, 2018

Is it possible to modify this example, so that when an input is focused, the user can press enter to submit the form?

I understand that the problem is that the input is not inside the form.
There has to be a way to do this though.

@ckosloski
Copy link
Contributor

I use the ng-keyup to detect enter and then submit the form

Add this to the edtiable- span
data-e-ng-keyup="$event.keyCode == 13 && submitForm('submitForm{{::$index}}')"

My button definition

<button type="submit" name="submitForm" id="submitForm{{::$index}}" data-ng-disabled="bookform.$waiting" class="btn btn-primary phonePaddingSmall" aria-label="Save">
                                    <i class="glyphicon glyphicon-floppy-disk" aria-hidden="true"></i>
                                </button>

My functions:

                    $scope.submitForm = function (id) {
                        commonFunctions.clickElement(id);
                    };
                clickElement: function(id) {
                    $timeout(function() {
                        angular.element("#" + id).trigger('click');
                    }, 50);
                },

@amfsyn
Copy link
Author

amfsyn commented Dec 21, 2018

Do you think it's technically possible to replace the entire row with an enclosed <form> on edit? I know that's a big ask, but it would preserve native form behavior.

@amfsyn
Copy link
Author

amfsyn commented Dec 21, 2018

I ran with what you gave me and created a simple directive that makes the solution easy. If you put this on the table's <tr> you can really easily add submit on enter.

app.directive('submitOnEnter', function () {
    return {
        link: function (scope, element, attrs) {
            $(element).keypress((event) => {
                if (event.keyCode === 13) { // <enter>
                     $(element).find('form').find(':submit').click();
                }
            })
        }
    }
});

Do you think this would be fit for a PR?

@ckosloski
Copy link
Contributor

Sure, go for it!!

@mochsner
Copy link

mochsner commented Dec 7, 2020

@amfsyn any reason this wasn't actually merged? I think this would still be really useful.

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

No branches or pull requests

3 participants