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

Fix stale combobox items displayed when search query changed #1918

Merged
merged 5 commits into from
Jan 21, 2022
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
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Changelog
2.2.0 (unreleased)
------------------

- #1918 Fix stale combobox items displayed when search query changed
- #1917 Fix wrong context in reference widget lookups
- #1916 Provide the request record to object info adapters in the sample add form
- #1913 Ported PR #1865 for dexterity contents
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -510,8 +510,7 @@
return;
}
options = JSON.parse(field.attr("combogrid_options"));
url = this.get_base_url();
url += "/" + options.url;
url = options.url;
url += "?_authenticator=" + (this.get_authenticator());
url += "&catalog_name=" + catalog_name;
url += "&colModel=" + (JSON.stringify(options.colModel));
Expand All @@ -532,7 +531,8 @@
options.url = url;
options.force_all = "false";
field.combogrid(options);
return field.attr("search_query", "{}");
field.attr("search_query", "{}");
return field.trigger("blur");
};

AnalysisRequestAdd.prototype.set_reference_field = function(field, uid, title) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -491,9 +491,11 @@ class window.AnalysisRequestAdd
# get the combogrid options
options = JSON.parse field.attr "combogrid_options"

# we have absolute URLs now
# https://github.com/senaite/senaite.core/pull/1917
url = options.url

# prepare the new query url
url = @get_base_url()
url += "/#{options.url}"
url += "?_authenticator=#{@get_authenticator()}"
url += "&catalog_name=#{catalog_name}"
url += "&colModel=#{JSON.stringify options.colModel}"
Expand All @@ -519,10 +521,12 @@ class window.AnalysisRequestAdd
options.url = url
options.force_all = "false"


field.combogrid options
field.attr "search_query", "{}"

# close on any open searchbox to force reload on the next focus
field.trigger("blur")


set_reference_field: (field, uid, title) =>
###
Expand Down
19 changes: 13 additions & 6 deletions src/senaite/core/browser/widgets/referencewidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,25 @@ def process_form(self, instance, field, form, empty_marker=None,
uid = None
return uid, {}

def get_search_url(self, context):
"""Prepare an absolute search url for the combobox
"""
# ensure we have an absolute url for the current context
url = api.get_url(context)
# normalize portal factory urls
url = url.split("portal_factory")[0]
# ensure the search path does not contain already the url
search_path = self.url.split(url)[-1]
# return the absolute search url
return "/".join([url, search_path])

def get_combogrid_options(self, context, fieldName):
colModel = self.colModel
if "UID" not in [x["columnName"] for x in colModel]:
colModel.append({"columnName": "UID", "hidden": True})

# ensure we have an absolute url for the current context
url = api.get_url(context)
search_path = self.url.split(url)[-1]
search_url = "/".join([url, search_path])

options = {
"url": search_url,
"url": self.get_search_url(context),
"colModel": colModel,
"showOn": self.showOn,
"width": self.popup_width,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,6 @@ function referencewidget_lookups(elements) {
}
};

if (window.location.href.search("portal_factory") > -1) {
options.url = window.location.href.split("/portal_factory")[0] + "/" + options.url;
}
options.url = options.url + "?_authenticator=" + $("input[name='_authenticator']").val();
options.url = options.url + "&catalog_name=" + $(element).attr("catalog_name");
options.url = options.url + "&base_query=" + $(element).attr("base_query");
Expand Down