I want to implement a Radio Button Group where every Radio Button will have a picture next to it (on the left side of the radio button).
Is that possible? If so, how?
html:
<div class="form-group" show-errors>
<label class="col-md-2 control-label metric-light-16-black pay-form-label">Payment Method</label>
<div class="col-md-10" id="rdPaymentMethod">
<label class="radio-group col-md-2">
<span id="radio-group-1" style="margin-left: 0cm;"></span>
<span class="radio" style="margin-left: 0cm;" />
<img src="assets/images/card-mastercard.png" style="margin-left: 0cm;"/>
</label>
<label class="radio-group col-md-2">
<span id="radio-group-2" style="margin-left: 0cm;"></span>
<span class="radio"/>
<img src="assets/images/card-viza.png"/>
</label>
<label class="radio-group col-md-2">
<span id="radio-group-3" style="margin-left: 0cm;"></span>
<span class="radio"/>
<img src="assets/images/card-paypal.png"/>
</label>
</div>
</div>
javascript sap function:
var placeRadioButtonAt = function(radioButtonId, containingDivId, selected) {
elements.push(radioButtonId);
var oRB1 = new sap.ui.commons.RadioButton(radioButtonId, {
selected : (selected==true),
select : function() {}
});
oRB1.placeAt(containingDivId);
}
calling this function 3 time (for each radio button):
placeRadioButtonAt("radio1","radio-group-1",true);
placeRadioButtonAt("radio2","radio-group-2");
placeRadioButtonAt("radio3","radio-group-3");
To use a custom image in a radio button control or a checkbox control, ensure the Add display image check box is selected. If you right-click on the Display field, this will open a prompt allowing the user to select an image on either the Reporting Server or WebFOCUS Client.
We will use radio buttons to select the image that we want to see from the image slider by giving an unique id to each radio button. Next, we will embed all the images one by one and create labels for radio button id's and will apply necessary CSS properties to achieve the desired output.
Radio buttons allow a user to select a single option among multiple options. You can set the Choice Value of each option, for each button, as well as group these buttons by giving them the same Group Name.
I would extend the RadioButton control for allowing images to be added with each radio button, and also extend the RadioButtonGroup to allow adding the previous extended control as an aggregation.
OBS: css classes rendering are missing, more details on renderer implementation can be found here.
Assumptions:
my.app
inside the index.html
filecontrols
sap.ui.define(['jquery.sap.global', 'sap/m/Image', 'sap/m/RadioButton'
], function (jQuery, Image, RadioButton) {
"use strict";
var CustomRadioButton = RadioButton.extend("my.app.controls.RadioButtonImage", {
metadata: {
"properties": {
"imageSrc": "string"
},
},
renderer: function (oRm, oControl) {
var oImg = new Image({ src: oControl.getProperty("imageSrc") })
oRm.renderControl(oImg);
sap.m.RadioButtonRenderer.render(oRm,oControl);
}
});
return CustomRadioButton;
}, true);
sap.ui.define(['jquery.sap.global', 'sap/m/RadioButtonGroup'
], function (jQuery, RadioButtonGroup) {
"use strict";
var CustomRadioButtonGroup = RadioButtonGroup.extend("my.app.controls.RadioButtonGroup", {
metadata: {
aggregations: {
buttons : {type : "my.app.controls.RadioButtonImage", multiple : true, singularName : "button", bindable : "bindable"}
},
defaultAggregation : "buttons",
}
});
return CustomRadioButtonGroup;
}, true);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With