setting options from task using custom html view

I've cutomised the choice recipe because I want to use a datalist rather than radio buttons. I have it working with hard coded options in the datalist, but I want to read the options from the task (i.e. task["options"]). Is there an example of this somewhere?

i.e. this doesn't work, presumably because options is a list of string, not of elements? I tried setting task['options'] = '<option value="option 1">' but that didn't work either?

<strong>{{text}}</strong>

<label for="points-input">Select the point from the list:</label>
<input required type="text" class="input" list="points-datalist" name="points" id="points-input" onchange="updateText()">
<datalist id="points-datalist">
   {{options}}
</datalist>

Hi! By "didn't work", do you mean that the markup was escaped so you ended up with the string instead of the rendered HTML?

Under the hood, the HTMl templating uses Mustache, which escapes HTML in variables by default – but according to the syntax reference, you can disable this with & and write {{& options}}.

Alternatively, a more elegant solution would probably be to store the option values in a more structured JSON format and then render it in the template, so you don't end up with all this HTML markup in your data. For example, assuming your JSON looks like this:

{
  "options": [
    {"id": 1, "text": "Option 1"},
    {"id": 2, "text": "Option 2"}
  ]
}

You could do the following in your template:

{{#options}}
  <option value="{{id}}">{{text}}</option>
{{/options}}

(The Mustache docs also have a live demo where you can try out different templates and JSON strucutres and see the resulting rendered markup.)

Edit: Btw, forgot to mention, in case you hadn't seen it yet: the text_input interface natively supports a datalist as well: https://prodi.gy/docs/api-interfaces#text_input

Thanks, it looks like the text_input pretty much does what I want. Although I'm now considering created a REST API as a "Knowledge Base" and using that as the source for the options. Since that's basically what I'm trying to do, step one is to extract the top level named entities and step two is to map them to a knowledge base of sorts (plus it's recursive so I think I'll combine text_input to link to the knowledge base, and ner_manual to extract more entities).