| View previous topic :: View next topic |
| Author |
Message |
jfkansas
Joined: 21 Jul 2008 Posts: 63
|
Posted: Mon Sep 14, 2009 3:54 pm Post subject: First upper once in spec form field |
|
|
Hello,
I'm just curious if a script/widget/document action exists which would force the first letter of the first and last name to uppercase. But, it would do this only one time so the user could go back and recapitalize another letter like in McDonald or a similar name which has more than one capital letter.
Thanks |
|
| Back to top |
|
 |
Steve
Joined: 17 Jan 2008 Posts: 337
|
Posted: Mon Sep 14, 2009 4:45 pm Post subject: Re: First upper once in spec form field |
|
|
| jfkansas wrote: | Hello,
I'm just curious if a script/widget/document action exists which would force the first letter of the first and last name to uppercase. But, it would do this only one time so the user could go back and recapitalize another letter like in McDonald or a similar name which has more than one capital letter.
Thanks |
There is nothing available and on scale to work in something as small as a script/widget/document action that will do Title Case with intelligent processing for things like "McD".
A script could easily be written to capitalize the first letter of a word in a form variable. _________________ Steve
You can read about other advanced tech topics on the http://www.insightsfour51.com/?cat=3 |
|
| Back to top |
|
 |
jfkansas
Joined: 21 Jul 2008 Posts: 63
|
Posted: Mon Sep 14, 2009 4:54 pm Post subject: |
|
|
Thanks,
I was looking through some javascript code from a competing system and they do the first upper once. I just don't know how/what to convert to use on Four51. There is a part of it that tests if it is the first time a user input in the field or the second.
This may need to be deleted for copyright issues. Just posting so you might see how this works.
// Upper casing and Lower Casing
/**************************************************
The code to change casing for Upper Once, Lower Once, and First Upper Once should not function in
the approval system. This is so if an approver makes a change to the text, the casing will not get
unintentionally changed.
***************************************************/
function UpperLower(bOption, sPromptName, sFormName){
// sInputString holds the user-entered imprint string
var sInputString = eval("window.document." + sFormName + "." + sPromptName);
// only set this variable if this function is called from the item info page because that is
// make the text Uppercase
if (bOption == 1)
{sInputString.value = sInputString.value.toUpperCase();}
// make the text lower
else if (bOption == 2)
{sInputString.value = sInputString.value.toLowerCase();}
// capitalize the first and lower the rest
else if (bOption == 3 && sFormName == 'ItemForm'){
// the only place that iPunctuation exists
// (Revision 61) iPunctuation holds the user-entered imprint string
var iPunctuationString = eval("window.document." + sFormName + ".iPunctuation");
// (Revision 61) this is the bit which determines if this function has been run for a prompt yet
var bFirstTime = eval("window.document." + sFormName + ".bFirstTime" + sPromptName);
// (Revision 61) if this is the first time this textbox has been changed AND it is the iteminfo screen and we are not editing
if (bFirstTime.value == '1' && sFormName == 'ItemForm' && iPunctuationString.value != '2') {
var sPreString;
var sPostString;
var sTempChar;
var sErrorMSGTempChar;
var sTempString = sInputString.value.toLowerCase();
var iStringLength = sTempString.length;
var sAlphaString = "abcdefghijklmnopqrstuvwxyz";
var bIsAlpha = 0;
// if the string has a length lets go
if (sTempString.length > 0){
// loop through this string and cap all the first characters
// in each word, and lower cap the rest
for (index = 0; index < iStringLength; index++){
if (index == 0){
sTempChar = sTempString.substring(0,1).toUpperCase();
sPostString = sTempString.substring(1,iStringLength);
sTempString = sTempChar + sPostString;
} else {
sTempChar = sTempString.substring(index, index+1);
if (sTempChar == " " && index < (iStringLength-1)) {
sTempChar = sTempString.substring(index+1, index+2).toUpperCase();
sPreString = sTempString.substring(0, index+1);
sPostString = sTempString.substring(index+2,iStringLength);
sTempString = sPreString + sTempChar + sPostString;
}
}
// (Revision 61) grab the current character
sErrorMSGTempChar = sInputString.value.substring(index, index+1);
bIsAlpa = 0;
for (c = 0; c < 26; c++){
if (sInputString.value.substring(index, index+1).toLowerCase() == sAlphaString.substring(c,c+1)){
bIsAlpa = 1;
}
}
// (Revision 61) if it is not the first character and it is in the alphabet and the character before is not a space and it is a capital letter
if (index != 0 && bIsAlpha == 1 && sInputString.value.substring(index-1, index) != " " && sErrorMSGTempChar == sInputString.value.substring(index, index+1).toUpperCase()) {
// set this flag so the iteminfo.cfm page knows to show the alert for first upper
iPunctuationString.value = 1;
}
// (Revision 61) else if (it is the first character and it is in the alphabet and it is lower case) or (it is not the first character and it is in the alphabet and the character before is a space and it is a lower case letter or (it is not the first character and it is in the alpahabet and the character before is not a space and it is uppercase)
else if ((index == 0 && bIsAlpa == 1 && sErrorMSGTempChar == sInputString.value.substring(index, index+1).toLowerCase()) || (index != 0 && bIsAlpa == 1 && sInputString.value.substring(index-1, index) == " " && sErrorMSGTempChar == sInputString.value.substring(index, index+1).toLowerCase()) || (index != 0 && bIsAlpa == 1 && sInputString.value.substring(index-1, index) != " " && sErrorMSGTempChar == sInputString.value.substring(index, index+1).toUpperCase())) {
// set this flag so the iteminfo.cfm page knows to show the alert for first upper
iPunctuationString.value = 1;
}
} // end for loop
// set the new value
sInputString.value = sTempString;
} // end if
// (Revision 61) set the bit for this text box to 0 so we do not run this function again
bFirstTime.value = 0;
}//end if bFirstTime
}// end else if (bOption == 3)
//Upper Once
else if (bOption == 4 && sFormName == 'ItemForm'){
// the only place that iPunctuation exists
// (Revision 61) iPunctuation holds the user-entered imprint string
var iPunctuationString = eval("window.document." + sFormName + ".iPunctuation");
// (Revision 61) this is the bit which determines if this function has been run for a prompt yet
var bFirstTime = eval("window.document." + sFormName + ".bFirstTime" + sPromptName);
// (Revision 61) if this is the first time this textbox has been changed AND it is the iteminfo screen and we are not editing
if (bFirstTime.value == '1' && sFormName == 'ItemForm' && iPunctuationString.value != '2') {
sInputString.value = sInputString.value.toUpperCase();
bFirstTime.value = 0;
}
}
//Lower Once
else if (bOption == 5 && sFormName == 'ItemForm'){
// the only place that iPunctuation exists
// (Revision 61) iPunctuation holds the user-entered imprint string
var iPunctuationString = eval("window.document." + sFormName + ".iPunctuation");
// (Revision 61) this is the bit which determines if this function has been run for a prompt yet
var bFirstTime = eval("window.document." + sFormName + ".bFirstTime" + sPromptName);
// (Revision 61) if this is the first time this textbox has been changed AND it is the iteminfo screen and we are not editing
if (bFirstTime.value == '1' && sFormName == 'ItemForm' && iPunctuationString.value != '2') {
sInputString.value = sInputString.value.toLowerCase();
bFirstTime.value = 0;
}
}
return true;
} // end of the function UpperLower |
|
| Back to top |
|
 |
Steve
Joined: 17 Jan 2008 Posts: 337
|
Posted: Tue Sep 15, 2009 9:02 am Post subject: Overkilla and Bad Practice |
|
|
The first thing that jumps out is the use of "eval" which is the #1 security violation in JavaScript programming.
Second, I can't imagine why all this would need to be done just to make the first letter of every word capitalized.
Is that the full requirements? Capitalize the first letter of every word? _________________ Steve
You can read about other advanced tech topics on the http://www.insightsfour51.com/?cat=3 |
|
| Back to top |
|
 |
jfkansas
Joined: 21 Jul 2008 Posts: 63
|
Posted: Tue Sep 15, 2009 9:13 am Post subject: |
|
|
Yes, and the ability for the end user to override the lowercase part as needed. I think the second part is the more difficult as you stated in the original post.
The code I posted is actually three parts. One part is to force uppercase, the next part is to force all lowercase, these we can already do a couple of ways. Mixed in there is the force first upper once. This is all tied to an admin level form field option. |
|
| Back to top |
|
 |
jfkansas
Joined: 21 Jul 2008 Posts: 63
|
Posted: Tue Sep 15, 2009 9:20 am Post subject: |
|
|
| On the eval part, I suppose the user entering a name on a non financial part of an order was decided not to be a large enough security risk. This isn't our programming, it is just a tool we are phasing out in favor of Four51. |
|
| Back to top |
|
 |
Steve
Joined: 17 Jan 2008 Posts: 337
|
Posted: Tue Sep 15, 2009 9:27 am Post subject: |
|
|
OK, I can whip something up for use now and integration into the API later. First, I want to nail down the requirements so this will go smoothly.
1. On blur (leaving focus of textbox) change the first letter, and only the first letter, of every word to a capitalized letter.
2. Allow text to be edited further
a. Does the user need the ability to change the first letter to a lower case? _________________ Steve
You can read about other advanced tech topics on the http://www.insightsfour51.com/?cat=3 |
|
| Back to top |
|
 |
jfkansas
Joined: 21 Jul 2008 Posts: 63
|
Posted: Tue Sep 15, 2009 9:50 am Post subject: |
|
|
I wouldn't think a person would need the first letter of a first or last name as lower case. It usually is a third letter like in McDonald or DeWitt.
In most cases this is to prevent the end user from entering their name in all uppercase letters. So it is actually changing all but the first letter to lower case. Then let the user selectively choose another letter to capitalize if needed.
Thanks for your help. |
|
| Back to top |
|
 |
Steve
Joined: 17 Jan 2008 Posts: 337
|
Posted: Tue Sep 15, 2009 10:07 am Post subject: |
|
|
Well, I'm way off in what you are looking for. Let me try again.
1. On blur change every letter to lowercase, except the first letter of each word.
2. Allow editing that overrides the lowercase rules by the user.
This complicates the issue. You'd have to concede that the "fixing" would only occur after the first blur. _________________ Steve
You can read about other advanced tech topics on the http://www.insightsfour51.com/?cat=3 |
|
| Back to top |
|
 |
jfkansas
Joined: 21 Jul 2008 Posts: 63
|
Posted: Tue Sep 15, 2009 10:51 am Post subject: |
|
|
Right, first blur only, and probably work both ways in case a user input their name in all lower case letters (it does happen).
1. Change first letter to upper if all are lower case.
2. Change all to lowercase except the first letter of each name/word.
3. Allow user to override the change after the first blur. |
|
| Back to top |
|
 |
Steve
Joined: 17 Jan 2008 Posts: 337
|
Posted: Tue Sep 15, 2009 1:12 pm Post subject: Temp fix |
|
|
OK, here is a little snippet of code that will do what you're asking. To use it you'll just need to register the plug in (TitleCase) with each spec you want to apply it to.
Plug in:
| Code: | $.fn.TitleCase = function() {
this.each(function() {
$.extend(this, {
init: function() {
$(this).blur(this.fix);
return this;
},
fired: false,
fix: function() {
if (!this.fired) {
var text = this.value.toLowerCase();
$(this).val(text).css('text-transform', 'capitalize');
}
this.fired = true;
}
});
return this.init();
});
}; |
To register to a spec:
| Code: | $(spec['specname']).TitleCase();
$(spec['morethanonespec']).TitleCase(); |
Just copy the plug in code and add the code for each spec you need to use this for in your advanced script tab. Make sure the plug in code is first (top of the script). Let me know if it works for you. _________________ Steve
You can read about other advanced tech topics on the http://www.insightsfour51.com/?cat=3 |
|
| Back to top |
|
 |
Steve
Joined: 17 Jan 2008 Posts: 337
|
Posted: Wed Sep 16, 2009 9:33 am Post subject: |
|
|
Does this not work for you? _________________ Steve
You can read about other advanced tech topics on the http://www.insightsfour51.com/?cat=3 |
|
| Back to top |
|
 |
jfkansas
Joined: 21 Jul 2008 Posts: 63
|
Posted: Thu Sep 17, 2009 10:20 am Post subject: |
|
|
We tried this out yesterday and it worked.
Thanks for the help on this. It is one of the features we were missing from the previous platform. |
|
| Back to top |
|
 |
Steve
Joined: 17 Jan 2008 Posts: 337
|
Posted: Thu Sep 17, 2009 11:56 am Post subject: |
|
|
OK, I will add this as a method to the Spec Form API. _________________ Steve
You can read about other advanced tech topics on the http://www.insightsfour51.com/?cat=3 |
|
| Back to top |
|
 |
Steve
Joined: 17 Jan 2008 Posts: 337
|
Posted: Thu Sep 17, 2009 12:20 pm Post subject: |
|
|
So, I went to add this to the API when I realized it's not necessary.
Just add this to your script:
| Code: | | $(spec['specname']).css('text-transform', 'capitalize'); |
And it will do what you want perfectly. It even corrects the letters as you type. _________________ Steve
You can read about other advanced tech topics on the http://www.insightsfour51.com/?cat=3 |
|
| Back to top |
|
 |
|