I'm having trouble getting the results in a Form Field to be formatted to all caps. Here's what I have for Field #44. What should I change?
Question
Question
Answer
While Steve's answer above is one way to do it, I think your original issue may just be an extraneous space in your CSS. From the provided code listing, I'm guessing you had assigned the "capitalizeMe" class to field 44? In which case that class is applied to the same element as the "q44" id. So when you have the selector "#q44 .capitalizeMe input" it looks for an input element within a "capitalizeMe" element within the "q44" element. This structure probably doesn't exist.
If you specifically want only the "#q44" element to follow this rule, the following two CSS statements are equivalent:
#q44 input {text-transform: capitalize;} /* Note there is no space between "#q44" and ".capitalizeMe" here. */ #q44.capitalizeMe input {text-transform: capitalize;} /* Admittedly, this is somewhat redundant. */
I would personally recommend the following:
.capitalizeMe input {text-transform: capitalize;}
as you would then be able to extend this behavior to other form fields simply by adding the "capitalizeMe" class to them, without having to also add their form field ID to the rule.
Personally, I would recommend in general to avoid adding selectors which use the form field ID, not just for reasons of easy extensibility, but also for ease of reference as to what is being targeted for the rule, for example if referring to the custom code to troubleshoot, or if someone else takes over the project and will have to work with the code. Even if the target of the rule is one specific field and it won't be applied to anything else, it's easier to understand what is targeted by ".zipcode input" than "#q17 input".
As a final caveat, potentially not relevant for your use, the "text-transform: capitalize" property will capitalize the first letter of any word (space-delimited) in the target element. In particular, it is not the same as "title case"; articles and short words like "of" will not get any special treatment. There are a few other interesting behaviors of the rule, more at the Mozilla Developer's reference.
Hope this helps!
Replies
Hi Connie
uppercase sets all text to UPPERCASE
lowercase sets all text to lowercase
capitalize makes the first character of the field a Capital
Here is the syntax you can use to change the case of your text in an input box.
44 representng the fields number.
#Field44 {text-transform: uppercase;}
#Field44 {text-transform: lowercase;}
#Field44 {text-transform: capitalize;}
If you are using the CSS class "capitalizeMe" with your field
.capitalizeMe input {text-transform:uppercase;}
Keep up the good work!
Steve
James and Steve: Thanks! The one that worked was:
#q44 input {text-transform:uppercase;}
So, both of you gave me pieces of the puzzle!
These ones did not work, for some reason:
#q44 {text-transform: uppercase;}
#q44 .capitalizeMe input {text-transform: uppercase;}
#q44 .capitalizeMe input{text-transform: uppercase;}
#q44.capitalizeMe input{text-transform:uppercase;} (no spaces)
#Field44 .capitalizeMe input {text-transform: uppercase;}
#Field44 {text-transform: uppercase;}
Hi all,
Thanks for posting this information. It certainly helped me out with a Forms project that requires the output to be in capitals. However, the
#qxx input {text-transform:uppercase;}
does work for multil-ine text fields or text fields that are in tables. Is there a way to alter it for those types of fields?
Thanks!
I had the same issue. Here's what I figured out...
I assigned a CSS class of upperCase to any field I wanted to show all caps (including table fields). At first, I used the {text-transform:uppercase;} command in CSS, but if I remember correctly, this was just a cosmetic change to the text on the form as you were viewing it. Once the form was submitted, the text values were not stored as upper case in the database.
This Javascript converts text to upper case as the end-user leaves the field and stores the values as upper case in the database...the "textarea" attribute covers multi-line fields:
$(document).ready(function(){ $('.upperCase input, textarea').focusout(function() { $( this ).val($( this ).val().toUpperCase()); }); });
Hope this helps!
Thanks for the information. That is very helpful.
Hi, I'm new to the software so it's no surprise that I can't make this work for me.
Here's what I have: Text boxes with first, middle and last name. also a box at the bottom with initials for who did the data entry. In the Advanced/CSS Class I have capitalizeMe. in the CSS for the first, middle, last name I have:
#q4.capitalizeMe input {text-transform: Capitalize;} (First)
#q5.capitalizeMe input {text-transform: Capitalize;} (Middle)
#q6.capitalizeMe input {text-transform: Capitalize;} (Last)
#q62.capitalizeMe input {text-transform: UpperCase;} (Init)
for the Javascript I have:
$(document).ready(function(){
$('.upperCase input, textarea').focusout(function() {
$( this ).val($( this ).val().toUpperCase());
});
});
$(document).ready(function(){
$('.Capitalize input, textarea').focusout(function() {
$( this ).val($( this ).val().toCapitalize());
});
});
When I fill out the form all is capitalized/uppercase. when I check the repository or run a report I get this:
If anyone has the patience to help me understand I would greatly appreciate it.
Donnie, I am certainly not an expert, however, one tip someone once gave me was to remove all other CSS and/or JavaScript. If the code you're working on then works, then it is something else interferring with your code. So, now, I will sometimes copy my form so I can play with it safely. Then copy and paste all the other code into another space to keep it handy, then delete it off the form process so I can test. Then, if my target code suddenly starts working, I will start copy/pasting my deleted stuff back in bit by bit until I find out where it stops working.
Hi Donnie, CSS and JS are very case dependent languages so Capitalize is not the same as capitalize. If you have added the CSS class CapitalizeMe (in the CSS Field under the Advanced Tab) to the fields you are targeting (First, Middle, Last and Initial) your CSS would be one of these examples below based on what you are looking for.
If you just want each First Letter to be Capitalized, ie John, then you would use:
.CapitalizeMe input {text-transform: capitalize;}
If you just want All Letters in the field to be UpperCase, ie JOHN, then you would use:
.CapitalizeMe input {text-transform: UpperCase;}
As in your example above, I would add the CSS Class Capitalize me to the First, Middle and Last Field, and add the Class UpperMe to the Initial Field
Then you would just need these two lines of CSS
.CapitalizeMe input {text-transform: capitalize;}
.UpperMe input {text-transform: UpperCase;}
You do not Require JS to make the CSS run
The CSS should work directly but in the case it does not, add !important at the end of the code as shown below
.CapitalizeMe input {text-transform: capitalize!important;}
.UpperMe input {text-transform: UpperCase!important;}
Steve, fo
Thanks for your reply and help. I did what you wrote as shown:
the form does capitalize/uppercase:
But it still doesn't carry over to the repository/report:
Am I still doing something wrong?
BTW Good Dog!
It appears the CSS is sylizing the text for display, but not actually changing the input data. In that case, you would need to use JS instead of the CSS to format the text.
I don't have any code to share with you at this moment, would need to dig into that a but further.
This is what I use, usually on name fields:
$(document).ready(function(){
//assign blur event to update value when user exits the field
$('#q21 input').blur(function(){
//get name and clean up leading/trailing whitespace
var name = $(this).val().trim();
//replace first letter of each word with uppercase
name = name.toLowerCase().replace(/\b[a-z]/g, function(letter) {
return letter.toUpperCase();
});
//save the updated value back into the field
$(this).val(name).change();
});
});
Connie,
Thanks for the code. I tried it with .blur and .focusout and neither worked. When I used this:
$(document).ready(function()
{
$('#q4 input').focusout(function()
{
$( this ).val($( this ).val().toUpperCase());
});
});
I got this (all uppercase. I used the formula for First #q4 & Last #q6 Name):
when I switched to this:
$(document).ready(function()
{
$('#q4 input').focusout(function()
{
$( this ).val($( this ).val().tocapitalize());
});
});
I got this (all lowercase. I used the formula for First #q4 & Last #q6 Name)
I'm getting an ice cream headache...
Huh, sorry, I can't help you troubleshoot. That is an exact copy of what is working in mine. I don't have enough experience to pick it apart and understand what might be wrong. Hopefully, someone else here will be able to help.