Jump to content

Changing button icon (svg) at runtime


Roberto Nicchi

Recommended Posts

I have found how to set a button icon then the button is initialized.

 

unibutton -> ClientEvents -> UniEvents -> beforeInit

function beforeInit(sender, config)
{
  config.icon='files/images/test.svg'
}

 

but, how to change it ?

 

With my poor JS knoledge i have tryed as follow:

 

thebut-> ClientEvents -> UniEvents -> afterCreate

function afterCreate(sender)
{
     sender.changeicon = function() {
      sender.icon='files/images/test2.svg';
     }
}

In a Tunibutton onclick event:

procedure TMainForm.UniButton1Click(Sender: TObject);
begin
  thebut.JSInterface.JSCall('changeicon')
end;

Doesn't have effect.

 

What's the right way ?

Link to comment
Share on other sites

57 minutes ago, Roberto Nicchi said:

I have found how to set a button icon then the button is initialized.

 

unibutton -> ClientEvents -> UniEvents -> beforeInit

function beforeInit(sender, config)
{
  config.icon='files/images/test.svg'
}

 

but, how to change it ?

 

With my poor JS knoledge i have tryed as follow:

 

thebut-> ClientEvents -> UniEvents -> afterCreate

function afterCreate(sender)
{
     sender.changeicon = function() {
      sender.icon='files/images/test2.svg';
     }
}

In a Tunibutton onclick event:

procedure TMainForm.UniButton1Click(Sender: TObject);
begin
  thebut.JSInterface.JSCall('changeicon')
end;

Doesn't have effect.

 

What's the right way ?

Ok i have found the solution

 

function afterCreate(sender)
{
     sender.changeicon = function() {
      sender.setIcon('files/images/test1.svg'); // <---- this is the correct code
     }
}

  • Like 1
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...