Prepare radio-button-group

This commit is contained in:
Daniel
2025-05-05 10:17:35 +02:00
committed by Markus Zolliker
parent f883c913ed
commit d6a69ba05e
3 changed files with 62 additions and 16 deletions

View File

@ -48,7 +48,7 @@
}
.row-waiting-for-answer {
background-color: LightGoldenrodYellow;
background-color: orangered;
}
/* ------------------------------ icon-modules ------------------------------ */
@ -143,12 +143,22 @@
/* ------------------------------ pushbutton ------------------------------ */
.push-button-active {
text-decoration: underline;
display: inline-block;
height: 20px;
padding: 0 4px 0 4px;
border-radius: 6px;
cursor: pointer;
text-align: center;
/* border: 1px solid #303030; */
color: #303030;
background: #dddddd;
/* box-shadow: 2px 4px 4px lightgray; */
}
.push-button-active:hover {
color: blue;
background: whitesmoke;
/* box-shadow: 1px 2px 2px dimgray; */
}
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */

View File

@ -300,13 +300,13 @@ function updateValue(component) {
let row = elem.closest('div');
row.classList.remove('row-waiting-for-answer');
let options = elem.childNodes;
for (var j = 0; j < options.length; j++) {
if (options[j].label == component.value) {
elem.value = j + 1;
}
}
} else if (type == "pushbutton") {
// let options = elem.childNodes;
// for (var j = 0; j < options.length; j++) {
// if (options[j].label == component.value) {
// elem.value = j + 1;
// }
// }
elem.value = component.value;
console.log('update pushbutton');
console.log('component.name:', component.name);
console.log('element', elem);

View File

@ -1,4 +1,4 @@
var writePermission = false;
var writePermission = true;
var showParams = false;
var showConsole = false;
var prompt = false // True while a prompt is opened.
@ -188,7 +188,7 @@ function createRightColumnForModules(component) {
component.type == 'checkbox' ||
component.type == 'enum'
) {
let input_element = createType(component);
let input_element = chooseTypeOfInput(component);
let icon_edit = createIconEdit(input_element);
right.appendChild(icon_edit);
right.appendChild(input_element);
@ -208,7 +208,7 @@ function createRightColumnForParameters(component) {
component.type == 'checkbox' ||
component.type == 'enum'
) {
let input_element = createType(component);
let input_element = chooseTypeOfInput(component);
let icon_edit = createIconEdit(input_element);
right.appendChild(icon_edit);
right.appendChild(input_element);
@ -255,7 +255,7 @@ function createIconEdit (input_element) {
return icon_edit;
}
function createType (component) {
function chooseTypeOfInput (component) {
let input_element;
switch (component.type) {
case 'enum':
@ -337,13 +337,13 @@ function createInputText(component) {
function createCheckbox(component) {
// Creates row-element containing checkbox-item
var input = createInputElement(component, 'input', 'parameter-checkbox');
let input = createInputElement(component, 'input', 'parameter-checkbox');
input.type = "checkbox";
input.onclick = function (e) {
e.stopPropagation;
}
var form = document.createElement('form');
let form = document.createElement('form');
form.onsubmit = function (e) {
e.preventDefault();
var row = form.closest('div');
@ -389,6 +389,42 @@ function createEnum(component) {
return right;
}
function createRadio(component) {
console.log(component);
let array_names = component.enum_names;
let form = createInputElement(component, 'form', 'radio-button-group');
form.onsubmit = function (e) {
e.preventDefault();
var row = form.closest('div');
row.classList.add('row-waiting-for-answer');
sendCommand(s, component.command + " " + 'on');
hideInputElements();
};
for (var i = 0; i < array_names.length; i++) {
let label = document.createElement('label');
label.setAttribute('for', array_names[i].title);
label.innerHTML = array_names[i].title;
let radio = document.createElement('input');
radio.setAttribute('type', 'radio');
radio.classList.add("radio");
radio.setAttribute('id', array_names[i].title);
radio.setAttribute('name', component.name);
radio.onclick = function(e) {
e.stopPropagation();
}
form.appendChild(label);
form.appendChild(radio);
}
form.appendChild(createSubmitButton());
return form;
}
function createInputElement(component, tag='span', cls='col-right-modules') {
var input_element = document.createElement(tag);
input_element.classList.add('col-right');