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

Set selected option by value #418

Merged
merged 2 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
22 changes: 13 additions & 9 deletions src/select/Select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -645,15 +645,7 @@

// if they set an inital value, look through our static options for it
if (changedProperties.has('value') && this.value && !this.values.length) {
if (this.staticOptions.length > 0) {
const existing = this.staticOptions.find(option => {
return this.getValue(option) === this.value;
});

if (existing) {
this.setValues([existing]);
}
}
this.setSelectedValue(this.value);
}

// default to the first option if we don't have a placeholder
Expand All @@ -666,6 +658,18 @@
}
}

public setSelectedValue(value: string) {
if (this.staticOptions.length > 0) {
const existing = this.staticOptions.find(option => {
return this.getValue(option) === value;
});

if (existing) {
this.setValues([existing]);

Check warning on line 668 in src/select/Select.ts

View check run for this annotation

Codecov / codecov/patch

src/select/Select.ts#L661-L668

Added lines #L661 - L668 were not covered by tests
}
}
}

private updateInputs(): void {
for (let ele = null; (ele = this.hiddenInputs.pop()); ) {
ele.remove();
Expand Down
1 change: 0 additions & 1 deletion src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ export const postUrl = (
body: payload,
};

console.log(options);
return new Promise<WebResponse>((resolve, reject) => {
fetch(url, options)
.then(async response => {
Expand Down
Loading