Closed ordigital closed 10 months ago
Changing label is no way to go. I had to modify sources to achieve this. Here is a solution:
In views.py
we take edit link to edit
variable:
def render_page(page):
if getattr(page, 'specific', None):
# For support of non-Page models like Snippets.
page = page.specific
if callable(getattr(page, 'autocomplete_label', None)):
title = page.autocomplete_label()
else:
title = page.title
edit = reverse('wagtailadmin_pages:edit', args=[page.id])
return dict(pk=page.pk, title=title, edit=edit)
In dist.js
we look for this code (prettify first!):
return e.createElement("div", {
key: n.pk,
className: ee("selection")
}, e.createElement("span", {
className: ee("selection__label")
}, n.title), e.createElement("button", {
type: "button",
className: ee("selection__button"),
onClick: t.handleRemove.bind(t, n)
}, e.createElement(k, {
className: ee("selection__icon")
}), e.createElement("span", {
className: ee("sr-only")
}, "Remove")))
}))))
and make it look like this:
return e.createElement("div", {
key: n.pk,
className: ee("selection")
}, e.createElement("span", {
className: ee("selection__label")
}, n.title),
e.createElement("div", {
className: ee("selection__controls")
},
// edit icon here
e.createElement("a", {
href: n.edit,
target: '__blank',
className: ee("edit__button")},
e.createElement("svg", {
className: ("icon icon-edit icon--item-action")},
e.createElement("use", { href: '#icon-edit'}),
)),
e.createElement("button", {
type: "button",
className: ee("selection__button"),
onClick: t.handleRemove.bind(t, n)
}, e.createElement(k, {
className: ee("selection__icon")
}), e.createElement("span", {
className: ee("sr-only")
}, "Remove"))))
}))))
Now we need to uninstall wagtail-autocomplete
from pip and put our wagtailautocomplete
folder with modified files directly to our app folder, where we have home
, search
etc. so it can be found by Wagtail.
This results in escaped characters instead of a working link to edit item. How to add working link to button/label?