Muhsin Muhsin - 5 months ago 215
Javascript Question

Input maxlength does not work on Android -Ionic

I have an input field and also i need to stop the user from typing more than the allowed character.

<input type="text" name="callsign" maxlength="7" >


It is working in browser.But not working on android devices?

Answer

Thanks for all your answers.Your answers didn't me a give a proper solution.Then i have created a directive for that.

directive.js

myApp.directive('limitChar', function() {
    'use strict';
    return {
        restrict: 'A',
        scope: {
            limit: '=limit',
            ngModel: '=ngModel'
        },
        link: function(scope) {
            scope.$watch('ngModel', function(newValue, oldValue) {
                if (newValue) {
                    var length = newValue.toString().length;
                    if (length > scope.limit) {
                        scope.ngModel = oldValue;
                    }
                }
            });
        }
    };
})

html

<input type="text" limit-char limit="7" >