Skip to content

Commit

Permalink
Merge pull request #312 from stelar7/patch-1
Browse files Browse the repository at this point in the history
Group radio buttons when setting query parameters
  • Loading branch information
shalvah authored Sep 2, 2021
2 parents bcfa76a + 0a1ad24 commit 2ff7c29
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions resources/js/tryitout.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,21 @@ async function executeTryOut(endpointId, form) {
const query = {};
const queryParameters = form.querySelectorAll('input[data-component=query]');
queryParameters.forEach(el => _.set(query, el.name, el.value));

// Group radio buttons by their name, and then set the checked value from that group
Array.from(queryParameters)
.filter(el => el.type === "radio")
.reduce(
(entryMap, el) => entryMap.set(el.name, [...(entryMap.get(el.name) || []), el]),
new Map()
)
.forEach((v, k) => {
v.forEach(el => {
if (el.checked) {
_.set(query, k, el.value);
}
});
});

let path = form.dataset.path;
const urlParameters = form.querySelectorAll('input[data-component=url]');
Expand Down

0 comments on commit 2ff7c29

Please sign in to comment.