Problem in using django-smart-selects the TabularInline or StackInline #27

rodolfo73 opened this Issue Dec 29, 2011 · 17 comments


None yet

For example, when using django-smart-selects the TabularInline in the class is inline with the "extra = 3" when I add a new account will appear three lines to be filled in these lines django-smart-selects will work, but if you add a new row it does not work anymore. This is the way you are doing bind the event in JS.

I'm going to be trying to come up with a solution for this in the near future..... hopefully tomorrow!

Any news on this bug ? Thanks ;)

Nope, sorry. Turned out that my project didn't need the smart selects after all. They were too simplistic for what I needed, so I am now generating dynamic forms with JavaScript.

dsm2005 commented Jan 16, 2013

I have this problem, too.

Me too.

Patrick, do you think you are going to fix this issue?

Thank you

gladson commented May 13, 2013

I have this same problem.


ghost commented Sep 12, 2013

same here.

I have attempted to make this work for a TabularInline by replacing the script generated by at line 73 with;

    <script type="text/javascript">
    (function($) {
        function fireEvent(element,event){
            if (document.createEventObject){
            // dispatch for IE
            var evt = document.createEventObject();
            return element.fireEvent('on'+event,evt)
            // dispatch for firefox + others
            var evt = document.createEvent("HTMLEvents");
            evt.initEvent(event, true, true ); // event type,bubbling,cancelable
            return !element.dispatchEvent(evt);

        function dismissRelatedLookupPopup(win, chosenId) {
            var name = windowname_to_id(;
            var elem = document.getElementById(name);
            if (elem.className.indexOf('vManyToManyRawIdAdminField') != -1 && elem.value) {
                elem.value += ',' + chosenId;
            } else {
                elem.value = chosenId;
            fireEvent(elem, 'change');

            var re_tabular = /-__prefix__-/;

            function fill_field(val, init_value, replacement){
                if (typeof replacement == 'undefined') 
                    replacement = [''];

                var ids = "#%(id)s".replace(re_tabular,replacement[0]);

                if (!val || val==''){
                    options = '<option value="">%(empty_label)s<'+'/option>';
                    $(ids + ' option:first').attr('selected', 'selected');

                $.getJSON("%(url)s/"+val+"/", function(j){
                    var options = '<option value="">%(empty_label)s<'+'/option>';
                    for (var i = 0; i < j.length; i++) {
                        options += '<option value="' + j[i].value + '">' + j[i].display + '<'+'/option>';
                    var width = $(ids).outerWidth();
                    if (navigator.appVersion.indexOf("MSIE") != -1)
                        $(ids).width(width + 'px');
                    $(ids + ' option:first').attr('selected', 'selected');
                    var auto_choose = %(auto_choose)s;
                        $(ids + ' option[value="'+ init_value +'"]').attr('selected', 'selected');
                    if(auto_choose && j.length == 1){
                        $(ids + 'option[value="'+ j[0].value +'"]').attr('selected', 'selected');

                var val = $("#id_%(chainfield)s").val();
                fill_field(val, "%(value)s");

                var replacement, is_tablular;
                is_tablular = re_tabular.test("#%(id)s");
                replacement = is_tablular ? $(this).attr('id').match(/-.*-/) || [''] : [''];

                var start_value = $("#%(id)s".replace(re_tabular,replacement[0])).val();
                var val = $(this).val();
                fill_field(val, start_value, replacement);
        if (typeof(dismissAddAnotherPopup) !== 'undefined') {
            var oldDismissAddAnotherPopup = dismissAddAnotherPopup;
            dismissAddAnotherPopup = function(win, newId, newRepr) {
                oldDismissAddAnotherPopup(win, newId, newRepr);
                if (windowname_to_id( == "id_%(chainfield)s") {
    })(jQuery || django.jQuery);

Seems to work ok except sometimes the $.getJSON xhr request returns an empty string which makes the j parameter undefined. This should be at least an empty array '[]' but not sure why this is happening.

mnayak commented Jan 22, 2014

Is there any update on this bug; has anyone found a solution?

essadek commented Jul 13, 2014

any upadate for this issue.
I tried davecanderson patch, but when I select in the first dropdown in the new added line the second dropdown of the first line is changed not the corresponding one.

onyekaa commented Oct 26, 2014

Would really love if we could get an update on this... having the same problem.

niotech commented Nov 3, 2014

anyone got this working out yet?


SalahAdDin commented Feb 9, 2015

Anyone could solve this issue? Many people have it!

knixeur commented Sep 3, 2015

I've got this working on PR #96 if you can please test it. Thanks!


SalahAdDin commented Sep 3, 2015


@jimmykobe1171 jimmykobe1171 added this to the new release milestone Jan 7, 2016

Any news? Thanks!

@blag blag added the Possibly fixed label Oct 13, 2016


blag commented Oct 13, 2016

Should be fixed by #148, PyPI release inbound (today or tomorrow).

Closing, but feel free to reopen if it's not. Thanks!

@blag blag closed this Oct 13, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment