Jump to content

Recommended Posts

Posted

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.

  • Administrators
Posted

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.

Posted

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

 

Thanks Farshad.

 

Good work with UniGUI.

Posted

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?

  • Administrators
Posted

i Think ,best mode is

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

begin

key:=#0;

end;

 

It does not work in web mode as keys aren't sent back to the browser. Such functionality should be implemented in client side.

Posted

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.

  • 1 year later...
Posted

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();
    }
 
     
}
Posted

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
  • 1 year later...

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...