Answer the question
In order to leave comments, you need to log in
Why are inputs grouped incorrectly?
Here is an example: https://codepen.io/Genri_Rus/pen/YzZoYWK
Now when you click on the group button, the corresponding fields appear below.
But why are they grouped a little wrong?
If you select one group, then everything is fine, but if there are several, then the arrNameInput array adds incorrectly
Answer the question
In order to leave comments, you need to log in
$('.form').on('submit', function (e) {
e.preventDefault();
const values = {};
$('.form__check').each(function () {
if ($(this).is(':checked')) {
const [name, ...keys] = $(this).attr('name').split('-');
if (name) {
(values[name] ??= []).push(keys.join('-'));
}
}
});
for (const key in values) {
$(`.inputs__value--${key}`).text(values[key].join(','));
}
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question