Skip to content

Commit 3899519

Browse files
authored
fix: searchable belongs_to field keep html tags on selected option (#2423)
1 parent ff357bc commit 3899519

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

app/javascript/js/controllers/search_controller.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ export default class extends Controller {
208208
handleOnSelect({ item }) {
209209
if (this.isBelongsToSearch) {
210210
this.updateFieldAttribute(this.hiddenIdTarget, 'value', item._id)
211-
this.updateFieldAttribute(this.buttonTarget, 'value', item._label)
211+
this.updateFieldAttribute(this.buttonTarget, 'value', this.removeHTMLTags(item._label))
212212

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

@@ -316,4 +316,10 @@ export default class extends Controller {
316316
target.setAttribute(attribute, value)
317317
target.dispatchEvent(new Event('input'))
318318
}
319+
320+
removeHTMLTags(str) {
321+
const doc = new DOMParser().parseFromString(str, 'text/html')
322+
323+
return doc.body.textContent || ''
324+
}
319325
}

0 commit comments

Comments
 (0)