Select one of available icons #5334
Answered
by
wezmag
milenkovicstefan
asked this question in
Help
-
How can I create custom editor to select one of available icons from ..\wwwroot\Content\site\custom\images for example? I'd like to create it like RadioButtonEditor but with images instead of text. |
Beta Was this translation helpful? Give feedback.
Answered by
wezmag
Jan 22, 2021
Replies: 1 comment 1 reply
-
You can create a custom editor inherit from RadioButtonEditor, and then override BTW, it's better to load data (id, image url, and etc...) from the database, rather than get file info directly from the directory. namespace YourProjectName {
@Serenity.Decorators.element('<div />')
@Serenity.Decorators.registerEditor([Serenity.IStringValue, Serenity.IReadOnly])
export class IconSelectEditor extends Serenity.RadioButtonEditor {
constructor(div: JQuery, opt: any) {
super(div, opt);
//load data from backend
//Common.IconService.ListIcons({}, response => {
// response.Icons.forEach(icon => {
// this.addRadio(icon.Value, icon.ImageUrl);
// });
//});
let images = [
{ value: '1', imageUrl: '/Content/site/custom/images/download_applicationnote.png' },
{ value: '2', imageUrl: '/Content/site/custom/images/download_compatibility.png' },
{ value: '3', imageUrl: '/Content/site/custom/images/download_datasheet.png' },
{ value: '4', imageUrl: '/Content/site/custom/images/download_driver.png' },
{ value: '5', imageUrl: '/Content/site/custom/images/download_manuls.png' }
];
images.forEach(image => {
this.addRadio(image.value, image.imageUrl);
});
}
protected addRadio(value: string, imageUrl: string) {
var label = $('<label/>').html(Q.format('<img src="{0}" />', imageUrl));
$('<input type="radio"/>').attr('name', this.uniqueName)
.attr('id', this.uniqueName + '_' + value)
.attr('value', value).prependTo(label);
label.appendTo(this.element);
}
}
} |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
milenkovicstefan
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can create a custom editor inherit from RadioButtonEditor, and then override
constructor
andaddRadio
methods.BTW, it's better to load data (id, image url, and etc...) from the database, rather than get file info directly from the directory.