Frederick Posted August 25, 2020 Share Posted August 25, 2020 I have a TUniSpinEdit control with a MinValue of 1 and a MaxValue of 12. In the OnExit event, I would like to read the entered value and then change it to either the MinValue or MaxValue depending on what is entered. However, the TUniSpinEdit(Sender).Value from within the OnExit event returns the MinValue or MaxValue selected by the control and not the displayed value. procedure TfrmMain.spnEditExit(Sender: TObject); var nValue : Integer; begin nValue:=TUniSpinEdit(Sender).Value; // How to read the displayed value? lblStatus.Caption:='Value: '+IntToStr(nValue)+', Text: '+TUniSpinEdit(Sender).Text; { if <displayed Value outside range> then TUniSpinEdit(Sender).Value:=nValue; // How to set the control's value. This line does nothing. } end; How do I get this to work? -- Frederick (UniGUI Complete - Professional Edition 1.90.0.1534) tunispinedit.mp4 Quote Link to comment Share on other sites More sharing options...
Sherzod Posted August 25, 2020 Share Posted August 25, 2020 3 hours ago, Frederick said: However, the TUniSpinEdit(Sender).Value from within the OnExit event returns the MinValue or MaxValue selected by the control and not the displayed value. Hello, You can try to use ClientEvents. 1. Don't use procedure TMainForm.UniSpinEdit1Exit(Sender: TObject); begin end; 2. ClientEvents... function afterCreate(sender) { sender.on('blur', function() { ajaxRequest(sender, 'blur', ['rawValue='+sender.getRawValue()]) }); } 3. OnAjaxEvent procedure TMainForm.UniSpinEdit1AjaxEvent(Sender: TComponent; EventName: string; Params: TUniStrings); begin if EventName = 'blur' then begin UniEdit1.Text := Params.Values['rawValue']; end; end; Quote Link to comment Share on other sites More sharing options...
Frederick Posted August 25, 2020 Author Share Posted August 25, 2020 3 hours ago, Sherzod said: . OnAjaxEvent procedure TMainForm.UniSpinEdit1AjaxEvent(Sender: TComponent; EventName: string; Params: TUniStrings); begin if EventName = 'blur' then begin UniEdit1.Text := Params.Values['rawValue']; end; end; Thanks. I manage to get the entered value but I want to change the entered value to the MinValue if the value is blank. procedure TMainForm.spnEditAjaxEvent(Sender: TComponent; EventName: string; Params: TUniStrings); var cValue : String; begin if EventName = 'blur' then begin cValue := Params.Values['rawValue']; if cValue='' then TUniSpinEdit(Sender).Text:=IntToStr(TUniSpinEdit(Sender).MinValue); // Nothing happens here end; end; However, the code to change the entered value does not work. Quote Link to comment Share on other sites More sharing options...
Sherzod Posted August 25, 2020 Share Posted August 25, 2020 22 minutes ago, Frederick said: if cValue='' then Why are you using this condition? Quote Link to comment Share on other sites More sharing options...
Frederick Posted August 25, 2020 Author Share Posted August 25, 2020 10 minutes ago, Sherzod said: Why are you using this condition? I want to check if nothing was entered. Quote Link to comment Share on other sites More sharing options...
Sherzod Posted August 25, 2020 Share Posted August 25, 2020 5 minutes ago, Frederick said: I want to check if nothing was entered. procedure TMainForm.UniSpinEdit1AjaxEvent(Sender: TComponent; EventName: string; Params: TUniStrings); begin if EventName = 'blur' then begin if Params.Values['rawValue'] = '' then with (Sender as TUniSpinEdit) do JSInterface.JSCall('setValue', [minValue]); end; end; Quote Link to comment Share on other sites More sharing options...
Frederick Posted August 25, 2020 Author Share Posted August 25, 2020 Thank you for the code. It works. I expanded it so that it automatically sets the minimum value if the entered value is below the minimum and the maximum value if it is above the maximum. procedure TMainForm.UniSpinEdit1AjaxEvent(Sender: TComponent; EventName: string; Params: TUniStrings); var cValue : String; begin if EventName = 'blur' then begin cValue := Params.Values['rawValue']; if (cValue = '') or (StrToInt(cValue)<TUniSpinEdit(Sender).MinValue) then with (Sender as TUniSpinEdit) do JSInterface.JSCall('setValue', [minValue]) else if (StrToInt(cValue) > TUniSpinEdit(Sender).MaxValue) then with (Sender as TUniSpinEdit) do JSInterface.JSCall('setValue', [maxValue]); end; end; Quote Link to comment Share on other sites More sharing options...
Frederick Posted October 11, 2023 Author Share Posted October 11, 2023 Why is the above code not working in UniGUI 1.90.0.1573? cValue always returns a blank value regardless of the value entered. Quote Link to comment Share on other sites More sharing options...
Frederick Posted October 11, 2023 Author Share Posted October 11, 2023 Scratch the above post. It works correctly after I removed a commented code in the TUniSpinEdit's OnExit event. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.