Tell me how to organize multiple data selection in your own input field? By the way this is done by default: enter image description here I’m trying to use Select2TagsField, but I don’t understand how to fill it with data, when I try to select, it displays No matches found :

 class CustomModelView(ModelView): form_columns = ('things_list',) form_extra_fields = { 'things_list': Select2TagsField( 'Things', data=['asdfasdf','asfdasdfasfasfd'], coerce=int ), } 

Result:

enter image description here

Tried to fasten a related decision , but in this case it does not display anything at all: enter image description here

    1 answer 1

    If you use WTForms, it has a FieldList, which in turn can contain one or more fields for each FieldList element.

     class IPV4(Form): ip = TextField('IPv4', validators=[validators.Required()]) mask = TextField('Маска', default='255.255.254.0', validators=[validators.Required()]) class Network(Form): ipv4 = FieldList(FormField(IPV4), min_entries=1) 

    Sampling is already immediately upon receipt of data

     @app.route('/form', methods=['GET', 'POST']) def form(): dataform = Network(request.form) if request.method == 'POST': for ipv4 in dataform.ipv4.data: data[0]['ipv4'].append({'ip': ipv4['ip'], 'netmask': ipv4['mask']}) return render_template('form.html', dataform=dataform) 

    Fields can be added dynamically via jQuery

    enter image description here

    • I have the biggest school just with the addition of new fields, since I do not know how to javascript. In general, I thought that I would add children first, then when I clicked the "add" button, x new fields will appear in the number, price (or IPv4, Mask, where x is the number of children) to which I’ll enter the data, Is it possible to do so? - aryndin
    • The question is not quite clear: If the goal is in the addition already on the form, then where is Python in principle? Then study JavaScript and immediately place the tags corresponding to the question, with its reformulation. If the issue is in resolution, then yes, I allow you to add exactly the predefined number of fields, but then you have to remove the empty ones in the script. I just have a plus done like this [+] and when clicked, the box below is added. - RemiZOffAlex
    • I explain: the variant with the variation of the number of fields on the form suits me, just how to organize it? Can you throw a little example? I just initially thought that clicking on the "add" button would trigger a script that would open a new window (or change the form - as you suggest) with the required number of fields (depending on the number of children), where I will add more. data. And so it turns out you gave the answer with the code, in writing which I have no special difficulties, and added "Fields can be added dynamically via jQuery" - like "learn javascript yourself," while I have a problem with it. Besides. - aryndin
    • You are free to supplement the questions. I'm looking for a suitable tool, and javascript is just one of them - so why add it to tags? - aryndin
    • Yes, apparently, I confused the answer to this question with the answer to this - ru.stackoverflow.com/questions/528281/… . :-))) - aryndin