Jump to content

Button with loader


bbm

Recommended Posts

When the button is pressed, an action is carried out in the background. As long as the action is being carried out, the loader should be visible. In my case, the button sits on a form that is automatically closed after an action has been performed.

Link to comment
Share on other sites

Hello

You can try below code. You can play with css to customize.

UniServerModule.CustomCSS

.button--loading .x-btn-inner {
  visibility: hidden;
  opacity: 0;
}

.button--loading::after {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  margin: auto;
  border: 4px solid transparent;
  border-top-color: #000000;
  border-radius: 50%;
  animation: button-loading-spinner 1s ease infinite;
}

@keyframes button-loading-spinner {
  from {
    transform: rotate(0turn);
  }

  to {
    transform: rotate(1turn);
  }
}

UniButton1->ClientEvents->UniEvents->ajaxRequest :

function ajaxRequest(sender, url, data)
{
  sender.setDisabled(true);
  sender.addCls('button--loading');
}

UniButton1->ClientEvents->UniEvents->ajaxCallback :

function ajaxCallback(sender, response)
{
  sender.setDisabled(false);
  sender.removeCls('button--loading');
}

To test, you can add sleep into button click event.

procedure TMainForm.UniButton2Click(Sender: TObject);
begin
  Sleep(5000);
end;

image.png.fa0664af5a3ca2c8f940242acee80346.png

Link to comment
Share on other sites

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