Skip to content

Commit

Permalink
Restore swap detail
Browse files Browse the repository at this point in the history
  • Loading branch information
nimmolo committed Jun 21, 2024
1 parent 6b8405e commit ce73d93
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions app/javascript/controllers/autocompleter_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,20 +168,23 @@ export default class extends Controller {
// Action may be called from a <select> with
// `data-action: "autocompleter-swap:swap->autocompleter#swap"`
// or an event dispatched by another controller.
swap(opts = {}) {
if (!this.hasSelectTarget)
return;
swap({ detail }) {
let type;

const type = this.selectTarget.value;
if (this.hasSelectTarget) {
type = this.selectTarget.value;
} else if (detail?.hasOwnProperty("type")) {
type = detail.type;
}

if (!AUTOCOMPLETER_TYPES.hasOwnProperty(type)) {
alert("MOAutocompleter: Invalid type: \"" + this.TYPE + "\"");
alert("MOAutocompleter: Invalid type: \"" + type + "\"");
} else {
this.TYPE = type;
this.inputTarget.setAttribute("data-type", type)
// add dependent properties and allow overrides
Object.assign(this, AUTOCOMPLETER_TYPES[this.TYPE]);
Object.assign(this, opts);
Object.assign(this, detail); // type, request_params
this.prepare_input_element();
}
}
Expand Down

0 comments on commit ce73d93

Please sign in to comment.