Preselected values with an ajax source in Flask

I seem unable to get the preselected values to work. I have tried quite a few things google offered me but nothing seems to work.

To try it, go to

Page is in Finnish, but don’t worry. Open “Käyttäjät” from the top menu and choose “Kirjaudu”. This opens a login page. Type admin/admin (this is just the development version running on a memory-base sqlite, so any changes you make will be reverted the following night).

The go to

Person field (“Henkilöt”) should have Niven, Larry (/Laurence Van Cott) as the value but it doesn’t. Search works perfectly fine.

So what am I doing wrong?

I couldn’t add a third link to the message so here’s the rest of the message:

Code is available from

(scripts are at the bottom of the file)

Console logs print what to me looks like correct data as well.

Line 93 is wrong:

var peopleSelect = $("#people-selector");

The selector should be .people-selector (a class selector), not #people-selector (an ID selector).

Simple mistake, and I’ve made it more than once myself.

Also, instead of the for loop on lines 101-108, you should just use the last element of the returned array:

var person = people[people.length -1];  // or, person = people.slice(-1);
var id =;
var name = person.text;
var option = new Option(name, id, true, true);

Figured that out with the help of a JS debugger but thanks for the message. Final issue I have seems to be with createTags, issue has persisted since at least 2015 but seems like it’s not going to be fixed.