I am looking to have a button from a jquery.ui with a icon.
My preferance is fontawsone, but I suppose bootstrap ones are ok.
So, say this markup:
<asp:Button ID="cmdTest" runat="server" Text="Test Dialog"
CssClass="btn"
OnClientClick="testdialog();return false;" />
<div id="fundialog" style="display:none">
<h3>This is a test dialog</h3>
<i class="fa fa-check-circle" aria-hidden="true"></i> Ok icon wanted
<br />
<i class="fa fa-times-circle" aria-hidden="true"></i> Cancel icon wanted
</div>
<br />
testing:<br />
<h4><i class="fa fa-car" aria-hidden="true"></i> Fa Car icon</h4>
<script>
function testdialog() {
var myDialog = $("#fundialog")
myDialog.dialog({
autoOpen: false,
modal: true,
closeText: "",
title: "My title Text",
appendTo: "form",
buttons: [
{
id: "MyOkBtn",
text: 'Ok',
class:'MyOkBtn',
click: function () {
myDialog.dialog('close')
myDialog.dialog('destroy');
btn.click()
}
},
{
id: "MyCancel",
text: "Cancel",
click: function () {
myDialog.dialog('close')
myDialog.dialog('destroy');
}
}
]
})
myDialog.dialog('open')
}
</script>
And the result is this:
However, as noted, I want a button with a icon.
I have attempted this:
buttons: [
{
id: "MyOkBtn",
text: '<i class="fa fa-check-circle" aria-hidden="true"></i>Ok',
click: function () {
myDialog.dialog('close')
myDialog.dialog('destroy');
btn.click()
}
},
but, result is this:
So, looking for a button, but a button with a icon from font awsome.
I suppose I am open to downloading a svg from boostrap ions, or even the fontawsome, and using a background image for the button.
So it does not look like jquery.ui buttons support any kind of button icon or image (other then some very old ugly ones that look like they came from windows 3.1 era).
While I am using asp.net here (web forms), it basic markup, jquery, jquery.ui.
I’m also open to modifying the jquery.ui css files, but they are quite long, and doing so would prevent future upgrades with any much ease.
There is also the looming issue of hover highlights, and the image color not changing, but hey, one step at a time!
2
Answers
I’m hoping you have a css file and you are using FontAwesome 6. Would be better to add the unicode form of the FA Icon via css like so,
Consider using the built in UI Icons:
You can use ID or Classes to make use of your own Icons too.
This method makes use of the
create
callback to modify the buttons and add the FontAwesome Icons.