Peter Gregory Posted April 24, 2013 Share Posted April 24, 2013 Hi, does anyone have any ideas about how i can make text first letter capitalised when entering into a TUniDBEdit control ? ProperCase - ie "John Smith" not "john smith" I have tried to use the following code in the OnKeyPress event but it doesnt work... if SurnameEdit.Text='' then key:=UpCase(Key) else if SurnameEdit.Text[length(surnameedit.text)]=' ' then key:=Upcase(key); is there some way to do this with javascript ? and where abouts would I put it ? any help would be gratefully reveived :-) thanksPeter Quote Link to comment Share on other sites More sharing options...
rencarnacion Posted April 24, 2013 Share Posted April 24, 2013 Try These in JavaScript : function capitaliseFirstLetter(string) {return string.charAt(0).toUpperCase() + string.slice(1);} Ronny Encarnacion Quote Link to comment Share on other sites More sharing options...
Sherzod Posted April 25, 2013 Share Posted April 25, 2013 Hi Peter. Try use CSS Text - text-transform. http://www.codertools.com/css_help_guide/css_text-transform.aspx http://www.w3schools.com/cssref/playit.asp?filename=playcss_text-transform&preval=capitalize Or Capitalize the first letter of all words in a string: function ucFirstAllWords( str ) { var pieces = str.split(" "); for ( var i = 0; i < pieces.length; i++ ) { var j = pieces[i].charAt(0).toUpperCase(); pieces[i] = j + pieces[i].substr(1); } return pieces.join(" "); } http://stackoverflow.com/questions/1026069/capitalize-the-first-letter-of-string-in-javascript Quote Link to comment Share on other sites More sharing options...
Sherzod Posted April 25, 2013 Share Posted April 25, 2013 The code in Delphi: procedure TMainForm.UniDBEdit1KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); function ToMixCase(InString: String): String; var i: Integer; begin if InString = '' then Exit; Result := LowerCase(InString); Result[1] := UpCase(Result[1]); For i := 1 to Length(InString) - 1 do begin if (Result[i] = ' ') //or (Result[i] = '''') //or (Result[i] = '"') //or (Result[i] = '-') //or (Result[i] = '.') //or (Result[i] = '(') Then Result[i + 1] := UpCase(Result[i + 1]); end; end; begin (Sender as TUniDBEdit).Text := ToMixCase((Sender as TUniDBEdit).Text) end; but this code does not work for unicode ... This code may not be optimal, but it is also one solution... http://www.esanu.name/delphi/Object%20Pascal/Strings/Capitalize%20the%20first%20letter%20of%20each%20word%20in%20a%20string.html Quote Link to comment Share on other sites More sharing options...
RobYost Posted August 30, 2017 Share Posted August 30, 2017 Using the delphi code eats some of the characters. I tried: UniSession.AddJS(' document.getElementById("' + edtTenantFirstName.JSName + '_id").style.textTransform = "capitalize"'); in UniFormShow But nothing seems to happen. I wasn't where to try this code: function ucFirstAllWords( str ) { var pieces = str.split(" "); for ( var i = 0; i < pieces.length; i++ ) { var j = pieces[i].charAt(0).toUpperCase(); pieces[i] = j + pieces[i].substr(1); } return pieces.join(" "); } Quote Link to comment Share on other sites More sharing options...
Sherzod Posted August 31, 2017 Share Posted August 31, 2017 Hi, Ok, can you try to use the fieldCls config for this ?: 1. ... function beforeInit(sender, config) { config.fieldCls='myEdit' } 2. CustomCSS: .myEdit { text-transform: capitalize; } Best regards, Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.