Quantcast

Page Forms: auto complete on a list of 1600 items

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Page Forms: auto complete on a list of 1600 items

Mark A. Hershberger-4
I'm trying to write a form where one field has ~1600 values.

I'm attempting to write a script that will return a list of matches and
using “values from url” to let the user supply tokens.

It does this, but not in the format that pageforms is expecting.

Right now it returns something like

    {"sfautocomplete":
        {"Earline's":451,
        "Gwendoline":619,…}}

But this isn't the format expected. What format should I be sending
back?

Mark.


--
Mark A. Hershberger
NicheWork LLC
717-271-1084

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Semediawiki-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/semediawiki-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Page Forms: auto complete on a list of 1600 items

Yaron Koren-2
Hi Mark,

I'm curious why you mentioned the number of values involved. Is this a
standard set of data, like the values of a property? If so, Page Forms'
standard functionality should be able to handle it - it can work with any
number of values.

You can see an example of the desired format linked to from here:

https://www.mediawiki.org/wiki/Extension:Page_Forms/
Input_types#From_an_outside_URL

Though you yourself modified this documentation just yesterday to fix the
link, so clearly you've seen the documentation - so I'm also curious about
that...

-Yaron

On Tue, May 9, 2017 at 1:02 AM, Mark A. Hershberger <[hidden email]>
wrote:

> I'm trying to write a form where one field has ~1600 values.
>
> I'm attempting to write a script that will return a list of matches and
> using “values from url” to let the user supply tokens.
>
> It does this, but not in the format that pageforms is expecting.
>
> Right now it returns something like
>
>     {"sfautocomplete":
>         {"Earline's":451,
>         "Gwendoline":619,…}}
>
> But this isn't the format expected. What format should I be sending
> back?
>
> Mark.
>
>
> --
> Mark A. Hershberger
> NicheWork LLC
> 717-271-1084
>
> ------------------------------------------------------------
> ------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Semediawiki-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/semediawiki-user
>



--
WikiWorks · MediaWiki Consulting · http://wikiworks.com
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Semediawiki-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/semediawiki-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Page Forms: auto complete on a list of 1600 items

Hermann Schwärzler
Hi Mark,

looking at the link to the example in the page Yaron just recommended,
your format should be
{"pfautocomplete":
  [
    {"Earline's":451},
    {"Gwendoline":619},
    ...
  ]
}

or
{"sfautocomplete":
   ...

shouldn't it? Note the array [] enclosing the name-value pairs...

Greetings
Hermann

On 05/09/2017 05:38 PM, Yaron Koren wrote:

> Hi Mark,
>
> I'm curious why you mentioned the number of values involved. Is this a
> standard set of data, like the values of a property? If so, Page Forms'
> standard functionality should be able to handle it - it can work with any
> number of values.
>
> You can see an example of the desired format linked to from here:
>
> https://www.mediawiki.org/wiki/Extension:Page_Forms/
> Input_types#From_an_outside_URL
>
> Though you yourself modified this documentation just yesterday to fix the
> link, so clearly you've seen the documentation - so I'm also curious about
> that...
>
> -Yaron
>
> On Tue, May 9, 2017 at 1:02 AM, Mark A. Hershberger <[hidden email]>
> wrote:
>
>> I'm trying to write a form where one field has ~1600 values.
>>
>> I'm attempting to write a script that will return a list of matches and
>> using “values from url” to let the user supply tokens.
>>
>> It does this, but not in the format that pageforms is expecting.
>>
>> Right now it returns something like
>>
>>     {"sfautocomplete":
>>         {"Earline's":451,
>>         "Gwendoline":619,…}}
>>
>> But this isn't the format expected. What format should I be sending
>> back?
>>
>> Mark.
>>
>>
>> --
>> Mark A. Hershberger
>> NicheWork LLC
>> 717-271-1084
>>
>> ------------------------------------------------------------
>> ------------------
>> Check out the vibrant tech community on one of the world's most
>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
>> _______________________________________________
>> Semediawiki-user mailing list
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/semediawiki-user
>>
>
>
>

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Semediawiki-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/semediawiki-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Page Forms: auto complete on a list of 1600 items

Mark A. Hershberger-4
In reply to this post by Yaron Koren-2

To clarify, I'm using Semantic Forms (PF before it was renamed).  But,
looking at the code in question (select2.js in this case), it looks like
the problem remains.

I've figured out the problem.  The answer was on the wiki page, but it
didn't slap me like I needed it to.  I documented my search (which you
can read below), but the answer is that PF needs your custom
autocompleter to provide JSON in the following form:

        {"sfautocomplete":
            [
                {"title":”OPTION ONE”},
                {"title":”OPTION TWO”},
                {"title":”OPTION THREE”},
                {"title":”OPTION FOUR”}
            ]
        }

I've expanded the documentation on mw.o so even a dolt like me should be
able to understand what is needed.

Now, for those of you who wanted to read a stream-of-conciousness
novella… read on!

Yaron Koren <[hidden email]> writes:

> I'm curious why you mentioned the number of values involved. Is this a
> standard set of data, like the values of a property? If so, Page Forms'
> standard functionality should be able to handle it - it can work with any
> number of values.

First, we've hit a wall at 100 values.  I'm sure this is something we're
doing wrong, but…

…the wiki isn't going to be the primary source for these values.  With
that in mind, I hope to ultimately provide a service that can query the
values.  I'm a fair bit along in that.

> Though you yourself modified this documentation just yesterday to fix the
> link, so clearly you've seen the documentation - so I'm also curious about
> that...

The documentation is not complete. To be fair, this isn't the fault of
Page Forms.

Page Forms uses select2.js[1] to provide the completion, so I went to
look at  the documentation for examples.  There is an FAQ about the
result format[2] that says “This answer to this question has not yet
been written.”

So, at least I'm not alone.

- - - - -

I've written a toy script to query a source and give results in json
format.

I must be doing something wrong because I keep seeing this error in the
js console (in addition to not seeing any results):
    TypeError: text is undefined 1 ext.sf.select2.base.js:251:4
        removeDiacritics https://example.dom/w/extensions/SemanticForms/libs/ext.sf.select2.base.js:251:4
        textHighlight https://example.dom/w/extensions/SemanticForms/libs/ext.sf.select2.base.js:258:23
        formatResult https://example.dom/w/extensions/SemanticForms/libs/ext.sf.select2.base.js:100:15
        populate https://example.dom/w/extensions/SemanticForms/libs/select2.js:920:39
        populateResults https://example.dom/w/extensions/SemanticForms/libs/select2.js:942:21
        updateResults/<.callback< https://example.dom/w/extensions/SemanticForms/libs/select2.js:1732:17
        bind/< https://example.dom/w/extensions/SemanticForms/libs/select2.js:672:17
        success https://example.dom/w/extensions/SemanticForms/libs/select2.js:460:25
        fire https://example.dom/w/load.php:3148:10
        fireWith https://example.dom/w/load.php:3260:7
        done https://example.dom/w/load.php:9314:5
        callback https://example.dom/w/load.php:9718:8

The URL http://example.dom/custom-autocomplete.php?l=lines&f=words
shows all the lines from the source (in this case, every 10th line from
/usr/share/dict/words) that matches “lines”.  This example results in:

        {"sfautocomplete":
            {"2435":{"id":"borderlines",
                            "value":"borderlines",
                            "label":"borderlines",
                            "text":"borderlines"},
                            …

I blatted the value over the keys “id”, “value”, “label” and “text”
because I saw each of them being use, but not why.

Anyway, PF is configured to read this correctly, so I can see that when
the user types “lines” an XHR request is made for
https://example.dom/w/api.php?action=sfautocomplete&format=json&external_url=tempURL&substr=lines&_=1494345628246
and it returns

    {"warnings": {
        "main": {
              "*": "Unrecognized parameter: '_'"
        }
    },
     "sfautocomplete": [
        {
          "id": "borderlines",
          "value": "borderlines",
          "label": "borderlines",
          "text": "borderlines"
        }, ....

So far, so good.

I'm instrumenting the code for select2.js (console.log() is your
friend!) and I can see that by the time we get to its populate() method
we have a list of objects that look like this:

     Object { id: 0, value: "borderlines", label: "borderlines", text: undefined }

Ok, I can see it substituting its own id so I'll take that out of my
results.

There is no difference.  (Well, the ordering is different — id now comes
at the end — but that is to be expected.)

Now, what happens if I take out text?

Same thing.  Ordering is different, but still shows up as undefined.

Output from my custom autocompleter now looks like this:

        {"sfautocomplete":
            {"2435":{"value":"borderlines",
                            "label":"borderlines"},
                            …

and the SMWApi is now giving

    {"warnings": {
        "main": {
              "*": "Unrecognized parameter: '_'"
        }
    },
     "sfautocomplete": [
        {
          "value": "borderlines",
          "label": "borderlines"
        }, ....

Still the same problem.  Let me try Hermann's suggestion and make my
output look like:

        {"sfautocomplete":
            [
                {"borderlines":”borderlines”},
                ....

Still, no results.  The resulting object does look like this, though:

     Object { id: 0, borderline: "borderlines", label: "borderlines", text: undefined }

Looking at my instrumented code and the traceback, I have found that the
transformation takes place in the call

    options.results(data, query.page);

at success callback around line 460 in select2.js.  This leads us back
to ajaxOpts.results() at line 251 in ext.sf.select2.tokens.js (since
this is the token input method I'm looking at) and, yep, it looks like I
should be putting something in the title attribute.

And, yay!, after changing the output of my custom autocomplete script
to:

        {"sfautocomplete":
            [
                {"title":”borderlines”,
                 “value”: ”borderlines”},
                ....

the autocompletes start working.  In fact, putting

        {"sfautocomplete":
            [
                {"title":”borderlines”}
                ....

is enough.

Footnotes:
[1]  https://select2.github.io/

[2]  https://select2.github.io/options.html#what-should-the-results-returned-to-select2-look-like


--
Mark A. Hershberger
NicheWork LLC
717-271-1084

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Semediawiki-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/semediawiki-user
Loading...