bacon Posted May 17, 2011 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.
Administrators Farshad Mohajeri Posted May 17, 2011 Administrators 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.
bacon Posted May 17, 2011 Author 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.
thecrgrt Posted May 19, 2011 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?
chatop Posted May 22, 2011 Posted May 22, 2011 i Think ,best mode is if not (key in ['0'..'9','.']) then begin key:=#0; end;
Administrators Farshad Mohajeri Posted May 22, 2011 Administrators 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.
thecrgrt Posted May 22, 2011 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.
rullomare Posted March 5, 2013 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(); } }
patmap Posted March 8, 2013 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
rullomare Posted March 8, 2013 Posted March 8, 2013 Hi Patmap, certainly wonderful solution, but more than one line! Best Regards
Sherzod Posted June 6, 2014 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
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now