Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typescript + Html: How to force uppercase in an input field

I'm working with angular (typescript) and I have a modelform in html where the user has to insert a code field and a description field.

The code field must always be entered by the user, always in uppercase.

I found and followed this question: How to convert input value to uppercase in angular 2 (value passing to ngControl)

but the last letter that the user inserts remains lowercase however .. The fundamental thing is that the database always comes in all uppercase (I also put a limit of 4 characters that works properly) this is my code now, but as written above it does not work properly:

<input type="text" id="code" #code class="form-control" formControlName="code" maxlength="4"                  (input)="code.value=$event.target.value.toUpperCase()"> 

has anyone found a quick, functional and fast solution?

thank you!

like image 667
Nobady Avatar asked May 21 '18 10:05

Nobady


People also ask

How do you force uppercase in HTML?

With upperCaseF() function on every key press down, the value of the input is going to turn into its uppercase form.

How do you capitalize input in JavaScript?

The toUpperCase() method converts a string to uppercase letters. The toUpperCase() method does not change the original string.

When you enter text into a input field a function is triggered which transforms the input text to upper case?

When you leave the input field, a function is triggered which transforms the input text to upper case.


1 Answers

You can simply add oninput="this.value = this.value.toUpperCase()" in your <input> tag and it will instantly convert any input in your input field to Uppercase.

like image 101
Ali Heikal Avatar answered Oct 08 '22 20:10

Ali Heikal