Page 1 of 1
How to force UPPERCASE letters?
Posted: 2020-08-11 18:58
by spizpan
Hi! I have searched the entier forum for this issue, but haven't found anything letaded... So the question is:
While someone is typing and inserting data through the form fields, how can i force the conversion to UPPERCASE letters?
Any assistance will be appreciated
Re: How to force UPPERCASE letters?
Posted: 2020-08-11 20:41
by pbottcher
Hi,
you can change the data in the hooks. Use the before_insert and before_update functions and use something like:
$data['YOURFIELDNAME']=strtoupper($data['YOURFIELDNAME']);
Re: How to force UPPERCASE letters?
Posted: 2020-08-12 02:01
by D Oliveira
another option on tablename_dv.js use javascript on change function .toUpperCase();
https://www.w3schools.com/jsref/jsref_touppercase.asp
Re: How to force UPPERCASE letters?
Posted: 2020-08-13 02:52
by zibrahim
As mentioned by D Oliveira, I use javascript in my TABLENAME-dv.js file in the hooks directory.
Create a new file and change the TABLENAME to yours.
Put the following code and don't forget to change the FIELDNAME to match with yours.
Code: Select all
// Set input to automatically convert to Uppercase. File hooks/tablename-dv.js
$j('#FIELDNAME').keyup(function () {
$j(this).val($j(this).val().toUpperCase());
});
Good luck.
Re: How to force UPPERCASE letters?
Posted: 2020-08-13 20:03
by spizpan
Thanks a lot guys for your replies.
So i use the code below, in my tablename-dv.js file, as mentioned by zibrahim
Code: Select all
// Set input to automatically convert to Uppercase.
$j('my_field_name').keyup(function () {
$j(this).val($j(this).val().toUpperCase());
});
but it doesn't seem to work. am i missing something?
Regards
Spiros
Re: How to force UPPERCASE letters?
Posted: 2020-08-13 23:33
by zibrahim
Hi Spiros
Can I know the tablename and the fieldname that you are using for this issue?
Re: How to force UPPERCASE letters?
Posted: 2020-08-13 23:47
by zibrahim
By the way,
I noticed that there is no # character before your FIELDNAME in your code. Perhaps that is the reason?
It should be
Code: Select all
$j('#my_field_name').keyup(function () {
$j(this).val($j(this).val().toUpperCase());
});
Re: How to force UPPERCASE letters?
Posted: 2020-08-14 17:58
by spizpan
zibrahim wrote: ↑2020-08-13 23:47
By the way,
I noticed that there is no # character before your FIELDNAME in your code. Perhaps that is the reason?
It should be
Hi Zibrahim,
Yes i was missing the
# character as i thought it was an example character. I incuded the
# character before the fieldname and again it did not to work....
BUT,
the clue for me was to insert the code on the top of TABLENAME-dv.js !!! As long as i had the code at the end of this file, the code did not respond. Now it does
Thanks a lot for your help mate!
Re: How to force UPPERCASE letters?
Posted: 2020-11-01 18:52
by aarlauskas
Thanks Ibrahim, very simple solution and very handy! Thank You!
Re: How to force UPPERCASE letters?
Posted: 2023-10-02 07:26
by yonder
zibrahim wrote: ↑2020-08-13 02:52
As mentioned by D Oliveira, I use javascript in my TABLENAME-dv.js file in the hooks directory.
Create a new file and change the TABLENAME to yours.
Put the following code and don't forget to change the FIELDNAME to match with yours.
Code: Select all
// Set input to automatically convert to Uppercase. File hooks/tablename-dv.js
$j('#FIELDNAME').keyup(function () {
$j(this).val($j(this).val().toUpperCase());
});
Good luck.
Hi zibrahim,
When i use that code it's working. However if i edit a record (for example the field is "name") and it has "Onder", i want to change the "n" and "d" characters, when i write "r" instead of "d" the cursor is going to end of the field. Is there a way to blocking it?
Best regards.
Re: How to force UPPERCASE letters?
Posted: 2023-10-02 10:49
by zibrahim
Hi there Yonder,
try this
Code: Select all
// Set input to automatically convert to Uppercase while maintaining cursor position
$j('#FIELDNAME').keyup(function () {
const startPos = (this).selectionStart;
const endPos = (this).selectionEnd;
(this).value = (this).value.toUpperCase();
(this).setSelectionRange(startPos, endPos);
});
I found this in the internet
https://stackoverflow.com/questions/542 ... f-the-text
Have a nice day.
Re: How to force UPPERCASE letters?
Posted: 2023-10-02 16:49
by yonder
zibrahim wrote: ↑2023-10-02 10:49
Hi there Yonder,
try this
Code: Select all
// Set input to automatically convert to Uppercase while maintaining cursor position
$j('#FIELDNAME').keyup(function () {
const startPos = (this).selectionStart;
const endPos = (this).selectionEnd;
(this).value = (this).value.toUpperCase();
(this).setSelectionRange(startPos, endPos);
});
I found this in the internet
https://stackoverflow.com/questions/542 ... f-the-text
Have a nice day.
zibrahim wrote: ↑2020-08-13 02:52
As mentioned by D Oliveira, I use javascript in my TABLENAME-dv.js file in the hooks directory.
Create a new file and change the TABLENAME to yours.
Put the following code and don't forget to change the FIELDNAME to match with yours.
Code: Select all
// Set input to automatically convert to Uppercase. File hooks/tablename-dv.js
$j('#FIELDNAME').keyup(function () {
$j(this).val($j(this).val().toUpperCase());
});
Good luck.
Hi zibrahim,
Yes it's working thanks. However i want to use the Turkish characters. If i use "ğüşöç" characters it can change to "ĞÜŞÖÇ" characters, but if i use "i" character it change it to "I" not "İ".
I was use the following code before your answer;
Code: Select all
$j('#pozisyon').keyup(function () {
$j(this).val($j(this).val().toLocaleUpperCase('tr-TR'));
So how can i use your code with "toLocaleUpperCase('tr-TR)" or how can i use your code with Turkish "İ" character?
Thank you so much.
Re: How to force UPPERCASE letters?
Posted: 2023-10-02 16:56
by yonder
Hello again,
Sorry, i just found the solution
Code: Select all
$j('#FIELDNAME').keyup(function () {
const startPos = (this).selectionStart;
const endPos = (this).selectionEnd;
(this).value = (this).value.toLocaleUpperCase('tr-TR');
(this).setSelectionRange(startPos, endPos);
});
Now it's working. Thank you so much again zibrahim.