Skip to content

Commit

Permalink
fix: searchable belongs_to field keep html tags on selected option
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul-Bob committed Jan 29, 2024
1 parent f7c3d8c commit 95e6e5d
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion app/javascript/js/controllers/search_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ export default class extends Controller {
handleOnSelect({ item }) {
if (this.isBelongsToSearch) {
this.updateFieldAttribute(this.hiddenIdTarget, 'value', item._id)
this.updateFieldAttribute(this.buttonTarget, 'value', item._label)
this.updateFieldAttribute(this.buttonTarget, 'value', this.removeHTMLTags(item._label))

document.querySelector('.aa-DetachedOverlay').remove()

Expand Down Expand Up @@ -316,4 +316,10 @@ export default class extends Controller {
target.setAttribute(attribute, value)
target.dispatchEvent(new Event('input'))
}

removeHTMLTags(str) {
const doc = new DOMParser().parseFromString(str, 'text/html')

return doc.body.textContent || ''
}
}

0 comments on commit 95e6e5d

Please sign in to comment.