Home Restrict User on input field using Javascript in Android
Reply: 1

Restrict User on input field using Javascript in Android

Namit
1#
Namit Published in 2018-01-12 19:20:48Z

I try to restrict user from typing in input field in android when user get android keypad below all solution didn't worked

Tried Solutions:

  1. Preventdefault
  2. MaxLength
  3. Input maxlength does not work on Android -Ionic

Any way to do so?

Adrian Smith
2#
Adrian Smith Reply to 2018-01-12 19:55:55Z

The idiomatic way to disable an input field in HTML is using the disabled attribute:

https://www.w3schools.com/tags/att_input_disabled.asp

An example would be:

<form action="/action_page.php">
  First name: <input type="text" name="fname"><br>
  Last name: <input type="text" name="lname" disabled="disabled"><br>
  <input type="submit" value="Submit">
</form>

PreventDefault has nothing to do with disabling an input as far as I understand. MaxLength would in theory work, but it is hacky and not as apparent what the goal of the code is.

Disabled can be bound to however you like, just like any other attribute in Angular. So you could do something like [disabled]="shouldDisable()" where shouldDisable() is a method on the component that returns a truthy or falsy value.

Also, ion-input may have some special behavior, but I'm not aware of it. You can read further here: https://forum.ionicframework.com/t/how-to-disable-ion-input/42522

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.382882 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO