How to get data from two inputs without using form?

1

I want to do something like in Excel. I have two inputs and in each I type values. When I press ENTER I want to capture the values entered, how can I do this? NOTE: I'm using Angular 1.

<div class="descontoPromo">
    <input class="form-control depro" type="text" name="descontoPromocional" ng-model="valor.descPromo" >
</div>
<div class="descontoFin">
    <input class="form-control defin" type="text" name="descontoFinanceiro" ng-model="valor.descFinan" >
</div>
    
asked by anonymous 26.03.2018 / 21:21

1 answer

2

Just capture the keydown event of $document from AngularJs , and call the function you want it to execute.

Demonstrate how to do this with the code below. both the function and the eventListener should be in the controller of the html you want to perform the function by enter.

This will not require a button, or even a form.

    function enter(e) {
        var keyCode = e.keyCode;
        if (keyCode == 13) {
            suaFuncao()
        } 
    }

    $document[0].addEventListener("keydown", enter, false);
    
27.03.2018 / 20:55