I
I
Infinite2018-04-04 13:39:04
Django
Infinite, 2018-04-04 13:39:04

django-select2 how to use with three tables?

There is a form for adding a characteristic, in it you need to make two dependent fields Characteristic and Value, the list in the Value field should change depending on the selected Characteristic, how to implement this correctly using django-select2 and the table structure attached below
5ac4ab0cc7831870568956.png
5ac4ab00ac4e2309005809.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2018-04-04
@Infinite

When changing the value in the CHARACTERISTIC field, send an ajax request to select valid values ​​and throw the response into values

$.ajax({
            method: 'post',
            data: data,
            type: 'json',
            success: function (responce) {
                var data = [{id: '', text: helpText, disabled: true, selected: true}];
                if (responce.data) {
                    responce.data.map(function (el) {
                        data.push(el);
                    });
                    $('#ЗНАЧЕНИЕ').select2('destroy').empty().select2({data: data});
                }
            },
            error: function (e) {
                console.log(e);
            }
        });

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question