How can I use radio buttons as input types in a Camunda user task form? I only found an older thread where apparently radio buttons are not supported
Does anyone have newer information?
How can I use radio buttons as input types in a Camunda user task form? I only found an older thread where apparently radio buttons are not supported
Does anyone have newer information?
I don't think radio buttons will ever be supported out-of-the-box in the embedded forms because their usage can vary a lot between use cases.
If you need to offer a choice (out of several possibilities) to the user, you can use the select element. If the select element really doesn't fit your needs, you can still use the cam-script directive to add your custom scripts.
This is how I use Radio Buttons in my forms:
<div class="controls">
<div class="form-group">
<div
aria-labelledby="item"
aria-required="false"
role="group"
class="form-radio radio"
>
<div class="checkbox form-check">
<label
for="item_1"
class="form-check-label label-position-right"
>
<span>1</span>
<input
role="radio"
id="item_1"
value="1"
lang="en"
class="form-check-input"
type="radio"
name="item-radio"
ref="input"
checked=""
/>
</label>
</div>
<div class="checkbox form-check">
<label
for="item_2"
class="form-check-label label-position-right"
>
<span>2</span>
<input
role="radio"
id="item_2"
value="2"
lang="en"
class="form-check-input"
type="radio"
name="item-radio"
ref="input"
/>
</label>
</div>
<input
type="hidden"
cam-variable-name="item"
cam-variable-type="String"
id="hidden_item"
ng-model="item"
autocomplete="off"
class="ng-untouched ng-valid ng-valid-cam-variable-type ng-not-empty ng-valid-parse ng-pristine"
value="2"
/>
</div>
And I apply event using javascript:
// Get all hidden input fields
var hiddenInputs = document.querySelectorAll('input[type="hidden"]');
hiddenInputs.forEach(function (hiddenInput) {
// Get the key from the id of the hidden input field
var key = hiddenInput.id.split("_")[1];
// Get all radio buttons in the same group
var radios = document.querySelectorAll(`input[name="${key}-radio"]`);
radios.forEach(function (radio) {
radio.addEventListener("change", function () {
if (this.checked) {
// Update the hidden input field with the value of the selected radio button
hiddenInput.value = this.value;
}
});
});
});
Currently I am working to make it cleaner but this works fine.