Skip to content

Commit a273e64

Browse files
authored
Merge pull request #277 from ahamelers/request-body-fix
Fix switching between request body examples
2 parents fa06aeb + d27c15d commit a273e64

1 file changed

Lines changed: 13 additions & 12 deletions

File tree

src/components/api-request.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ export default class ApiRequest extends LitElement {
384384
this.selectedRequestBodyExample = e.target.value;
385385
const exampleDropdownEl = e.target;
386386
window.setTimeout((selectEl) => {
387-
const exampleTextareaEl = selectEl.closest('.example-panel').querySelector('.request-body-param');
387+
const exampleTextareaEl = selectEl.closest('.example-panel').querySelector(`.request-body-param[data-example="${this.selectedRequestBodyExample}"`);
388388
const userInputExampleTextareaEl = selectEl.closest('.example-panel').querySelector('.request-body-param-user-input');
389389
userInputExampleTextareaEl.value = exampleTextareaEl.value;
390390
this.computeCurlSyntax();
@@ -501,19 +501,20 @@ export default class ApiRequest extends LitElement {
501501
.value="${this.fillRequestWithDefault === 'true' ? (displayedBodyExample.exampleFormat === 'text' ? displayedBodyExample.exampleValue : JSON.stringify(displayedBodyExample.exampleValue, null, 8)) : ''}"
502502
></textarea>
503503
</slot>
504-
505-
<!-- This textarea(hidden) is to store the original example value, this will remain unchanged when users switches from one example to another, its is used to populate the editable textarea -->
506-
<textarea
507-
class = "textarea is-hidden request-body-param ${reqBody.mimeType.substring(reqBody.mimeType.indexOf('/') + 1)}"
508-
spellcheck = "false"
509-
data-ptype = "${reqBody.mimeType}"
510-
style="width:100%; resize:vertical; display:none"
511-
.value="${(displayedBodyExample.exampleFormat === 'text' ? displayedBodyExample.exampleValue : JSON.stringify(displayedBodyExample.exampleValue, null, 8))}"
512-
></textarea>
513504
</div>`
514505
: ''}
515-
516-
</div>
506+
${reqBodyExamples.map((bodyExample) => html`
507+
<!-- This textarea(hidden) is to store the original example value, this will remain unchanged when users switches from one example to another, its is used to populate the editable textarea -->
508+
<textarea
509+
class = "textarea is-hidden request-body-param ${reqBody.mimeType.substring(reqBody.mimeType.indexOf('/') + 1)}"
510+
spellcheck = "false"
511+
data-ptype = "${reqBody.mimeType}"
512+
data-example = "${bodyExample.exampleId}"
513+
style="width:100%; resize:vertical; display:none"
514+
.value="${(bodyExample.exampleFormat === 'text' ? bodyExample.exampleValue : JSON.stringify(bodyExample.exampleValue, null, 8))}"
515+
></textarea>
516+
`)}
517+
</div>
517518
`;
518519
} else if (this.selectedRequestBodyType.includes('form-urlencoded') || this.selectedRequestBodyType.includes('form-data')) {
519520
bodyTabNameUseBody = false;

0 commit comments

Comments
 (0)