Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Group radio buttons when setting query parameters #312

Merged
merged 2 commits into from
Sep 2, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions resources/js/tryitout.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,19 @@ async function executeTryOut(endpointId, form) {
const query = {};
const queryParameters = form.querySelectorAll('input[data-component=query]');
queryParameters.forEach(el => _.set(query, el.name, el.value));
Copy link
Contributor

@shalvah shalvah Sep 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You know, I think this would have just been simpler:

    queryParameters.forEach(el => {
        if (el.type !== 'radio' || (el.type === 'radio' && el.checked)) {
            _.set(query, el.name, el.value);
        }
    });

I'll change it. Simpler is better. 😅

Array.from(queryParameters)
.filter(el => el.type === "radio")
.reduce(
(entryMap, e) => entryMap.set(e.name, [...(entryMap.get(e.name) || []), e]),
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