Django select list

15 views
Skip to first unread message

Sherif Adigun

unread,
May 25, 2020, 11:11:01 AM5/25/20
to Django users
I have a form which has a select field (your color). In front of the select field, I have a button that produces a popup which allows users to create new color before they submit. I am submitting that color form via Ajax. After adding a new color to the database, the popup closes.
I want the newly added color to show in the select list without reloading the page.

Is this possible?

Luqman Shofuleji

unread,
May 25, 2020, 2:57:33 PM5/25/20
to django...@googlegroups.com
Yes that's possible since you are using Ajax. It should be something like this:

            $.ajax({
                url'{% url "xxxx" %}',
                data: {
                    'xxxxx'xxxx,
                },
                dataType'json',
                successfunction (data) {
                    if (data.added_item) {
                        item = data.added_item
                        $("#selectListID").append(item);

                    }
                }
            });




--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/9f176d90-93e3-40f8-b02f-4d27b6b55a75%40googlegroups.com.

Luqman Shofuleji

unread,
May 25, 2020, 3:45:50 PM5/25/20
to django...@googlegroups.com
Little adjustment,


            $.ajax({
                url'{% url "xxxx" %}',
                data: {
                    'xxxxx'xxxx,
                },
                dataType'json',
                successfunction (data) {
                    if (data.added_item) {
                        item = "<option value = '" + data.added_item + " '>" + data.added_item + "</option>";
                        $("#selectListID").append(item);
                    }
                }
            });

Reply all
Reply to author
Forward
0 new messages