Jump to content

Question re capitalisation on TUniDBEdit


Peter Gregory

Recommended Posts

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 :-)

 

thanks

Peter

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • 4 years later...

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(" ");
} 
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...