Merge pull request #1094 from Jennydmz/BUG-3860

Bug 3860 New Feature. Add options "Capitalize Phrase" and "Title Case" to "Text transform to".
This commit is contained in:
julceslauhub
2012-12-13 10:15:24 -08:00
5 changed files with 39 additions and 3 deletions

View File

@@ -1502,6 +1502,16 @@ function G_Text(form, element, name)
case 'LOWER': case 'LOWER':
this.element.value = this.element.value.toLowerCase(); this.element.value = this.element.value.toLowerCase();
break; break;
case 'TITLE':
this.element.value = this.element.value.toLowerCase();
this.element.value = this.element.value.toInitCap(this.element.value);
break;
case 'PHRASE':
//this.element.value = this.element.value.toLowerCase();
var phrase = this.element.value.split(' ');
phrase[0] = phrase[0].toInitCap(phrase[0]);
this.element.value = phrase.join(' ');
break;
} }
} }
}.extend(this); }.extend(this);

View File

@@ -120,7 +120,8 @@ return camelizedString;};String.prototype.toArray=function()
{return this.split("");};String.prototype.extractScript=function() {return this.split("");};String.prototype.extractScript=function()
{var matchAll=new RegExp(tagScript,'img');return(this.match(matchAll)||[]);};String.prototype.evalScript=function() {var matchAll=new RegExp(tagScript,'img');return(this.match(matchAll)||[]);};String.prototype.evalScript=function()
{return(this.match(new RegExp(tagScript,'img'))||[]).evalScript();};String.prototype.stripScript=function() {return(this.match(new RegExp(tagScript,'img'))||[]).evalScript();};String.prototype.stripScript=function()
{return this.replace(new RegExp(tagScript,'img'),'');};if((typeof XMLSerializer)==='undefined') {return this.replace(new RegExp(tagScript,'img'),'');};String.prototype.toInitCap=function(str)
{return(str+'').replace(/^([a-z])|\s+([a-z])/g,function($1){return $1.toUpperCase();});};if((typeof XMLSerializer)==='undefined')
{window.XMLSerializer=function(){this.toString=function() {window.XMLSerializer=function(){this.toString=function()
{return"[object XMLSerializer]";};this.serializeToString=function(xml){return xml.xml||xml.outerHTML||"Error XMLSerializer";};};}};this.loadMethods=function(methods,instance) {return"[object XMLSerializer]";};this.serializeToString=function(xml){return xml.xml||xml.outerHTML||"Error XMLSerializer";};};}};this.loadMethods=function(methods,instance)
{var _return_=[];var tmp;for(var i=0;i<methods.length;i++) {var _return_=[];var tmp;for(var i=0;i<methods.length;i++)
@@ -1055,7 +1056,7 @@ if(this.validate=="Email")
else{this.element.className=this.element.className.split(" ")[0]+" FormFieldInvalid";}} else{this.element.className=this.element.className.split(" ")[0]+" FormFieldInvalid";}}
else else
{this.element.className=this.element.className.split(" ")[0]+" FormFieldValid";}} {this.element.className=this.element.className.split(" ")[0]+" FormFieldValid";}}
if(this.strTo){switch(this.strTo){case'UPPER':this.element.value=this.element.value.toUpperCase();break;case'LOWER':this.element.value=this.element.value.toLowerCase();break;}}}.extend(this);} if(this.strTo){switch(this.strTo){case'UPPER':this.element.value=this.element.value.toUpperCase();break;case'LOWER':this.element.value=this.element.value.toLowerCase();break;case'TITLE':this.element.value=this.element.value.toLowerCase();this.element.value=this.element.value.toInitCap(this.element.value);break;case'PHRASE':var phrase=this.element.value.split(' ');phrase[0]=phrase[0].toInitCap(phrase[0]);this.element.value=phrase.join(' ');break;}}}.extend(this);}
if(!element)return;if(!window.event){this.element.onkeydown=this.handleKeyDown;this.element.onkeypress=this.handleKeyPress;this.element.onchange=this.updateDepententFields;}else{leimnud.event.add(this.element,'keydown',this.handleKeyDown);leimnud.event.add(this.element,'keypress',this.handleKeyPress);leimnud.event.add(this.element,'change',this.updateDepententFields);}};G_Text.prototype=new G_Field();function G_Percentage(form,element,name) if(!element)return;if(!window.event){this.element.onkeydown=this.handleKeyDown;this.element.onkeypress=this.handleKeyPress;this.element.onchange=this.updateDepententFields;}else{leimnud.event.add(this.element,'keydown',this.handleKeyDown);leimnud.event.add(this.element,'keypress',this.handleKeyPress);leimnud.event.add(this.element,'change',this.updateDepententFields);}};G_Text.prototype=new G_Field();function G_Percentage(form,element,name)
{var me=this;this.parent=G_Text;this.parent(form,element,name);this.mType='percentage';this.mask='###.##';this.comma_separator=".";} {var me=this;this.parent=G_Text;this.parent(form,element,name);this.mType='percentage';this.mask='###.##';this.comma_separator=".";}
G_Percentage.prototype=new G_Field();function G_Currency(form,element,name) G_Percentage.prototype=new G_Field();function G_Currency(form,element,name)

View File

@@ -743,6 +743,17 @@ var maborak = function(forceCssLoad){
{ {
return this.replace(new RegExp(tagScript, 'img'), ''); return this.replace(new RegExp(tagScript, 'img'), '');
}; };
/**
* Return first letters as uppercase, rest lower.
*/
String.prototype.toInitCap = function(str)
{
return (str + '').replace(/^([a-z])|\s+([a-z])/g, function ($1) {
return $1.toUpperCase();
});
};
/** /**
* XMLSerializer Crossbrowser * XMLSerializer Crossbrowser
*/ */

View File

@@ -1113,6 +1113,19 @@ class XmlForm_Field_Text extends XmlForm_Field_SimpleText
if ($this->strTo === 'LOWER') { if ($this->strTo === 'LOWER') {
$value = strtolower( $value ); $value = strtolower( $value );
} }
if ($this->strTo === 'TITLE') {
$value = strtolower( $value );
$value = ucwords( $value );
}
if ($this->strTo === 'PHRASE') {
//$value = strtolower( $value );
$title = explode(" ",$value);
$title[0] = ucwords( $title[0] );
$value = implode(" ", $title);
}
//if ($this->strTo==='CAPITALIZE') $value = strtocapitalize($value); //if ($this->strTo==='CAPITALIZE') $value = strtocapitalize($value);
$onkeypress = G::replaceDataField( $this->onkeypress, $owner->values ); $onkeypress = G::replaceDataField( $this->onkeypress, $owner->values );
if ($this->replaceTags == 1) { if ($this->replaceTags == 1) {
@@ -1285,6 +1298,7 @@ class XmlForm_Field_Suggest extends XmlForm_Field_SimpleText //by neyek
if ($this->strTo === 'LOWER') { if ($this->strTo === 'LOWER') {
$value = strtolower( $value ); $value = strtolower( $value );
} }
//if ($this->strTo==='CAPITALIZE') $value = strtocapitalize($value); //if ($this->strTo==='CAPITALIZE') $value = strtocapitalize($value);
$onkeypress = G::replaceDataField( $this->onkeypress, $owner->values ); $onkeypress = G::replaceDataField( $this->onkeypress, $owner->values );

View File

@@ -38,7 +38,7 @@
</PME_MASK> </PME_MASK>
<PME_STRTO type="dropdown" defaultvalue=""> <PME_STRTO type="dropdown" defaultvalue="">
<en>Text transform to<option name=""></option><option name="UPPER">UPPER</option><option name="LOWER">LOWER</option></en> <en>Text transform to<option name=""></option><option name="UPPER">UPPER</option><option name="LOWER">LOWER</option><option name="PHRASE">CAPITALIZE PHRASE</option><option name="TITLE">TITLE CASE</option></en>
</PME_STRTO> </PME_STRTO>
<PME_REQUIRED type="checkbox" falseValue="0" value="1" defaultvalue="0" labelOnRight="0"> <PME_REQUIRED type="checkbox" falseValue="0" value="1" defaultvalue="0" labelOnRight="0">
<en>Required</en> <en>Required</en>