Jump to content

How To Read TUniSpinEdit's Displayed Value And Change It If It Is Outside The Range?


Frederick

Recommended Posts

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)
 

Link to comment
Share on other sites

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;

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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;

 

Link to comment
Share on other sites

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;

Link to comment
Share on other sites

  • 3 years 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...