Page MenuHomePhabricator

Displaytitle not honored
Open, Needs TriagePublic

Description

If populating a combobox with values from a category and the list exceeds some limit, say 100 entries or so (where nothing is immediately
displayed but need to be searched) the list (when typing) of matched item will display the pagename rather than it's displaytitle, a chosen value from this list will however again show the title.

Also tokens element seem effected. See attached example

Al

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald TranscriptSep 4 2020, 12:59 PM
Aklapper updated the task description. (Show Details)Sep 4 2020, 3:19 PM
Jisraelsson updated the task description. (Show Details)Sep 4 2020, 3:28 PM
Jisraelsson updated the task description. (Show Details)Sep 4 2020, 4:10 PM

All though my programming skill are rusty to say the least I'm quite certain this solves the problem. May I kindly ask someone to have a look ?

diff --git a/libs/ext.pf.select2.combobox.js b/libs/ext.pf.select2.combobox.js
index 15e9b2be..93cdf658 100644
--- a/libs/ext.pf.select2.combobox.js
+++ b/libs/ext.pf.select2.combobox.js
@@ -241,10 +241,11 @@
                        processResults: function (data) { // parse the results into the format expected by Select2.
                                if (data.pfautocomplete !== undefined) {
                                        data.pfautocomplete.forEach( function(item) {
-                                               item.id = item.title;
                                                if (item.displaytitle !== undefined) {
+                                                       item.id = item.displaytitle;
                                                        item.text = item.displaytitle;
                                                } else {
+                                                       item.id = item.title;
                                                        item.text = item.title;
                                                }
                                        });
diff --git a/libs/ext.pf.select2.tokens.js b/libs/ext.pf.select2.tokens.js
index e961c661..55244b4a 100644
--- a/libs/ext.pf.select2.tokens.js
+++ b/libs/ext.pf.select2.tokens.js
@@ -311,10 +311,11 @@
                        processResults: function (data) { // parse the results into the format expected by Select2.
                                if (data.pfautocomplete !== undefined) {
                                        data.pfautocomplete.forEach( function(item) {
-                                               item.id = item.title;
                                                if (item.displaytitle !== undefined) {
+                                                       item.id = item.displaytitle;
                                                        item.text = item.displaytitle;
                                                } else {
+                                                       item.id = item.title;
                                                        item.text = item.title;
                                                }
                                        });

@Jisraelsson: Thanks for taking a look at the code! You are very welcome to use developer access to submit the proposed code changes as a Git branch directly into Gerrit which makes it easier to review and provide feedback. If you don't want to set up Git/Gerrit, you can also use the Gerrit Patch Uploader. Thanks again!

Change 630831 had a related patch set uploaded (by Gerrit Patch Uploader; owner: Jisraelsson):
[mediawiki/extensions/PageForms@master] For tokens and combobox, use displaytitle if avalible - T262040

https://gerrit.wikimedia.org/r/630831

YOUR1 added a subscriber: YOUR1.Oct 29 2020, 7:03 AM
This comment was removed by YOUR1.

This change doesn't work as expected. You introduce a new bug by changing item.id = item.displaytitle, while it 'looks' okay; it's really not, because once you save the form, the selected value will be the displaytitle, and not the pagetitle (id) of the page.

For example; you have a page with DisplayTitle 'bar' and the page ID is foo. Once you select 'bar' the property would be stored as 'bar' and not as 'foo', thus when saving, bar is used instead of 'foo'.

@YOUR1 that is not the behavior we are experiencing. The title is only displayed in the form whereas it's value (the actual pagename) is saved.
What version of Pageform are you using ?

YOUR1 added a comment.EditedOct 29 2020, 3:42 PM

I tested it with pageforms 4.9.5; field definition:

{{{field|...|input type=tokens|mapping property=Display title of|list|values from category=...}}}

Also I might add, the category contains +50k results, thus only a couple (1000 by default) are shown. That's why the mapping fails probably.

Your filed definition works fine in my setup (pagename is saved). Running git-master version of pageforms. I however only have 100+ entries in my category.

YOUR1 added a comment.EditedOct 29 2020, 4:21 PM

I think you set $wgPageFormsMaxAutocompleteValues to 25 or something to reproduce it.