This is a migrated thread and some comments may be shown as answers.

How to change the text of a button

3 Answers 842 Views
Toolbar
This is a migrated thread and some comments may be shown as answers.
Tim
Top achievements
Rank 1
Tim asked on 20 Feb 2018, 11:05 PM

Hello,

I'm looking for a way to change the text of a toolbar button. I was hoping the following would work:

$("$myButton").text("My text");

 

Unfortunately, that also replaces the ImageUrl. Can you please tell me a supported way of changing the text?

3 Answers, 1 is accepted

Sort by
0
Tim
Top achievements
Rank 1
answered on 21 Feb 2018, 03:53 PM

I ended up writing the following function:

function SetTextNodeValue(command, text) {
    var textNode = $(command).contents().filter(function () {
        return this.nodeType === Node.TEXT_NODE;
    }).get(0);
 
    if (!textNode) {
        return;
    }
 
    textNode.nodeValue = text;
}

 

I'm not crazy about this because it assumes a certain structure for element(s) of the the KendoToolbar item. If this changes in a future release, my function may not work anymore.

I think we could use a few more API methods for updating some of the properties on the toolbar items, such as the text of a button. A good use case for allowing text to be updated is for a single toggle button such as a Play/Stop button. Another example can be found right on your demo page found here. In this demo, you have a "Hide Repeat" / "Show Repeat" button. If this button had an image, the code in your demo would break since you're also updating the native element with assumptions on it's structure.

Regards,
Tim

0
Ivan Danchev
Telerik team
answered on 22 Feb 2018, 03:15 PM
Hello Tim,

We agree that having API methods that allow individual ToolBar items options to be set would be useful to have. We would suggest logging your idea in our public Feedback Portal. Based on the support it receives it can get approved by the team and the functionality implemented in a subsequent release.

Regards,
Ivan Danchev
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Tim
Top achievements
Rank 1
answered on 22 Feb 2018, 05:18 PM
Thank you, I have posted my idea as suggested.
Tags
Toolbar
Asked by
Tim
Top achievements
Rank 1
Answers by
Tim
Top achievements
Rank 1
Ivan Danchev
Telerik team
Share this question
or