Здравствуйте, у меня есть 2 входа, где один - это режим, а мой второй вход зависит от первого, чтобы показать параметры, которые я сделал до сих пор:
const data = [{
id: 1,
name: "SIMPLES NACIONAL – MEI",
funcionarioIncrease: 49.99,
maxFuncionario: 1,
socioIncrease: 0,
maxSocio: 5,
FATURAMENTO: [{
id: 1,
name: "ATÉ 30.000,00",
value: 49.99,
},
{
id: 2,
name: "De 30.001,00 a 50.000,00 ",
value: 99.99,
},
],
},
{
id: 2,
name: "SIMPLES NACIONAL – SERVIÇOS",
funcionarioIncrease: 25,
maxFuncionario: 3,
socioIncrease: 25,
maxSocio: 5,
FATURAMENTO: [{
id: 1,
name: "ATÉ 30.000,00",
value: 149.99,
},
{
id: 2,
name: "De 30.001,00 a 50.000,00 ",
value: 199.99,
},
],
},
];
function createInput(id) {
var inputRadio = document.createElement("input");
if (id) {
inputRadio.id = id;
inputRadio.name = "category";
inputRadio.type = "radio";
inputRadio.value = id;
inputRadio.classList.add("radio");
return inputRadio;
}
return null;
}
function creteFatuOptions() {
const container = document.querySelector(".faturamento-container");
const mode = document.querySelector(".selected").getAttribute('data-value')
data.forEach((value) => {
if (value.id == mode) {
var optionDiv = document.createElement("div");
optionDiv.id = ("ft")
optionDiv.classList.add("option");
container.append(optionDiv);
value.FATURAMENTO.forEach((faturamento) => {
var input = createInput(faturamento.id);
if (!input) {
return null;
}
optionDiv.append(input);
var label = document.createElement("label")
label.htmlFor = value.id;
label.innerHTML = faturamento.name;
optionDiv.append(label);
})
}
});
}
function createModeOptions() {
const container = document.querySelector(".options-container");
data.forEach((value) => {
const optionDiv = document.createElement("div");
optionDiv.classList.add("option");
container.append(optionDiv);
const input = createInput(value.id);
if (!input) {
return null;
}
optionDiv.append(input);
var label = document.createElement("label");
label.htmlFor = value.id;
label.innerHTML = value.name;
optionDiv.append(label);
});
}
function selectFaturamento(id) {
creteFatuOptions();
const selectedFaturamento = document.querySelector(
"div#selected-faturamento"
);
const faturamentoContainer = document.querySelector(".faturamento-container");
const optionsList = document.querySelectorAll("div#ft");
selectedFaturamento.addEventListener("click", () => {
faturamentoContainer.classList.toggle("active");
});
optionsList.forEach((o) => {
o.addEventListener("click", () => {
let input = o.querySelector("input").id;
selectedFaturamento.innerHTML = o.querySelector("label").innerHTML;
selectedFaturamento.setAttribute("data-value", input);
faturamentoContainer.classList.remove("active");
});
});
}
function selectMode() {
createModeOptions();
const selectedMode = document.querySelector("div#serviceMode");
const optionsContainer = document.querySelector(".options-container");
const optionsList = document.querySelectorAll(".option");
data.forEach((item) => {
if ((item.id = 1)) {
selectedMode.innerHTML = item.name;
selectedMode.setAttribute("data-value", item.id);
}
}), {
once: true
};
selectedMode.addEventListener("click", () => {
optionsContainer.classList.toggle("active");
});
optionsList.forEach((o) => {
o.addEventListener("click", () => {
let input = o.querySelector("input").id;
selectedMode.innerHTML = o.querySelector("label").innerHTML;
selectedMode.setAttribute("data-value", input);
optionsContainer.classList.remove("active");
});
});
}
function initalize() {
selectMode();
selectFaturamento();
}
initalize();
.option {
border-radius: 8px;
}
.select-box {
display: flex;
width: 100%;
max-height: 50px;
flex-direction: column;
position: relative;
z-index: 2;
}
.select-box .options-container {
padding: 0;
background: #fff;
color: #000;
max-height: 0;
width: 100%;
opacity: 0;
transition: all 0.4s;
border: 1px solid #dadada;
border-radius: 8px;
position: absolute;
overflow: hidden;
order: 1;
top: 120%;
z-index: 2;
}
.select-box .options-container::after {
position: absolute;
display: block;
content: "";
bottom: 100%;
right: 25px;
width: 7px;
height: 7px;
margin-bottom: -3px;
border-top: 1px solid #dadada;
border-left: 1px solid #dadada;
background: #fff;
transform: rotate(45deg);
transition: all 0.4s ease-in-out;
}
.selected {
width: 100%;
font-size: 1rem;
outline: none;
border: 1px solid #dadada;
border-radius: 5px;
padding: 1rem 0.7rem;
color: orange;
transition: 0.1s ease-out;
position: relative;
order: 0;
}
.selected::after {
position: absolute;
display: block;
content: "";
width: 10px;
height: 10px;
top: 50%;
right: 25px;
border-bottom: 1px solid #dadada;
border-right: 1px solid #dadada;
transform: rotate(45deg) translateY(-50%);
transition: all 0.4s ease-in-out;
transform-origin: 50% 0;
transition: all 0.4s;
}
.select-box .options-container.active {
max-height: 240px;
opacity: 1;
padding: 10px 0;
overflow: visible;
}
.select-box .options-container.active+.selected::after {
margin-top: 3px;
transform: rotate(-135deg) translateY(-50%);
}
.select-box .options-container::-webkit-scrollbar {
width: 8px;
background: #fff;
border-radius: 0 8px 8px 0;
}
.select-box .options-container::-webkit-scrollbar-thumb {
background: #dadada;
border-radius: 0 8px 8px 0;
}
.select-box .option,
.selected {
padding: 12px 24px;
cursor: pointer;
}
.select-box label {
cursor: pointer;
color: orange;
}
.select-box label:hover {
color: orange;
}
.select-box .option .radio {
display: none;
}
<div id="service" class="custom_select flex">
<h3 class="textfield_label">
Selecione a categoria da sua Empresa
</h3>
<div class="select-box">
<div class="options-container"></div>
<div id="serviceMode" class="selected">
Selecione um Tipo de Serviço
</div>
</div>
</div>
<div id="faturamento" class="custom_select flex">
<h3 class="textfield_label">
Selecione o faturamento mensal da sua Empresa
</h3>
<div class="select-box">
<div class="faturamento-container options-container"></div>
<div id="selected-faturamento" class="selected">
Qual o faturamento mensal?
</div>
</div>
</div>
но по какой-то причине в моем входном идентификаторе Faturamento значения должны были отображаться следующим образом:
if mode 1:
name: "ATÉ 30.000,00",
name: "De 30.001,00 a 50.000,00 ",
но по какой-то причине они появляются вместе
ATÉ 30.000,00, De 30.001,00 a 50.000,00