Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 70747

Number only directive works on pc but not in mobile

$
0
0

@PlasticSoul wrote:

Hi guys, I have a directive that allows user input only integer numbers, it’s working fine on desktop chrome and firefox, but it’s not working on device (it accepts dot and comma, for example).
Can you help me? Here is the code.
By the way, I just tried the input types: tel, number and text, it works only on desktop.

Template:

<ion-item>
<ion-label floating color="secondary">Levantamento Atual</ion-label>
<ion-input type="tel" formControlName="avaliacao_atual" integerOnly></ion-input>
</ion-item>

Directive:

import { Directive, HostListener } from '@angular/core';
@Directive({
    selector: '[integerOnly]'
})
export class NumberOnlyDirective {
    @HostListener('keypress')
    onkeypress(e) {
        let event = e || window.event;
        console.log(event);
        if (event) {
            return this.isNumberKey(event);
        }
    }
    isNumberKey(event) {
        console.log(event);
        let charCode = event.which ? event.which : event.keyCode;
        if (charCode > 31 && (charCode < 48 || charCode > 57)) {
            return false;
        }
        return true;
    }
}

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 70747

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>