Jump to content

How to number edits?


bacon

Recommended Posts

I want to know how I do to make an edit only accept numbers. in WinForms I do something like this in the keydown event 'if char not in [0..9] then char := #0;' but in uniGui this seens to not work in web mode, i put a breakpoint and it goes to the event, but it seens not to change the char value and the letter is accepted.

 

Thanks.

 

Best Regards.

 

Brian.

Link to comment
Share on other sites

  • Administrators

I want to know how I do to make an edit only accept numbers. in WinForms I do something like this in the keydown event 'if char not in [0..9] then char := #0;' but in uniGui this seens to not work in web mode, i put a breakpoint and it goes to the event, but it seens not to change the char value and the letter is accepted.

 

Thanks.

 

Best Regards.

 

Brian.

 

Setting Char parameter has no effect in web mode. Such a control should be implemented as a new Component. It is in issue list.

Link to comment
Share on other sites

Setting Char parameter has no effect in web mode. Such a control should be implemented as a new Component. It is in issue list.

IMO, it's easier to add EditType for TUniEdit and TUniDBEdit, when EditType is set to "Number" then use TExtFormNumberField instead of TExtFormTextField in Web-mode, is it possible?

Link to comment
Share on other sites

i Think ,best mode is

if not (key in ['0'..'9','.']) then

begin

key:=#0;

end;

The only way to work around is:

 

var
 AText: String;
begin
 AText := (Sender as TUniEdit).Text;
 if not (key in ['0'..'9','.']) then
 begin
   (Sender as TUniEdit).Text := AText;
 end;
end;

But I'dont like this way, this should be an asynchronous method using JavaScript.

Link to comment
Share on other sites

  • 1 year later...

post-1298-0-69867800-1362497421_thumb.png

Use ClientEvent  in Tuniedit  / TuniDbEdit . 
 
 
function OnKeypress(sender, e)
 {
  var allowed = "0123456789" ;
  var c = e.getCharCode() ;
  if (allowed.indexOf(String.fromCharCode ©  ) === -1 ) 
  {  
      e.stopEvent();
    }
 
     
}
Link to comment
Share on other sites

Hi,

 

This is very simple:

 

1) Make a Inherited class from TUniEdit (Ex: TUniNumberText = Class(TUniEdit) )

2) Then override Loaded method;

3) Write This line into Loaded Method:

 

  ExtEdit.MaskRe    := '/[0-9]/i';

 

Only one line !

 

Regards

  • Upvote 1
Link to comment
Share on other sites

  • 1 year later...

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...