bacon Posted May 17, 2011 Share Posted May 17, 2011 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 More sharing options...
Administrators Farshad Mohajeri Posted May 17, 2011 Administrators Share Posted May 17, 2011 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 More sharing options...
bacon Posted May 17, 2011 Author Share Posted May 17, 2011 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. Link to comment Share on other sites More sharing options...
thecrgrt Posted May 19, 2011 Share Posted May 19, 2011 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 More sharing options...
chatop Posted May 22, 2011 Share Posted May 22, 2011 i Think ,best mode is if not (key in ['0'..'9','.']) then begin key:=#0; end; Link to comment Share on other sites More sharing options...
Administrators Farshad Mohajeri Posted May 22, 2011 Administrators Share Posted May 22, 2011 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. Link to comment Share on other sites More sharing options...
thecrgrt Posted May 22, 2011 Share Posted May 22, 2011 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 More sharing options...
chatop Posted May 22, 2011 Share Posted May 22, 2011 if can support javascript code on client ,will be OK Link to comment Share on other sites More sharing options...
rullomare Posted March 5, 2013 Share Posted March 5, 2013 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 More sharing options...
patmap Posted March 8, 2013 Share Posted March 8, 2013 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 1 Link to comment Share on other sites More sharing options...
rullomare Posted March 8, 2013 Share Posted March 8, 2013 Hi Patmap, certainly wonderful solution, but more than one line! Best Regards Link to comment Share on other sites More sharing options...
Sherzod Posted June 6, 2014 Share Posted June 6, 2014 http://forums.unigui.com/index.php?/topic/3495-how-only-number-in-tunidbnumberedit-not-double-is-it-possible/&do=findComment&comment=16284 Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now