Remove all options from dijit.form.FilteringSelect

Alen picture Alen · May 30, 2011 · Viewed 10.5k times · Source

I need help withe deleting all options from FilteringSelect.

Html code of select:

        <select id="kat" dojoType="dijit.form.FilteringSelect" style="width:170px; height: 22px;" name="form[kategorija]">
            <option value="izbira">Izberi...</option>
            <?php
            $rezKat = $tabelaKategorij->dobiVseKategorije();
          foreach($rezKat as $rowKat):
    echo '<option id="optkat" value="'.$rowKat['id'].'">'.$rowKat['ime_kategorije'].'</option>';                         
endforeach;
        ?>
        </select>

The function for deleting all options

function izbrisiSeznam()
{
     var j;
     for (j = dojo.byId("kat").length - 1; j>=0; j--)
     {
        dojo.byId("kat").remove(j);
     }
}

When i call this function in..

$(document).ready(function () {
    izbrisiSeznam();
});

Then works perfectly. But when i try to call function in onSuccess then doesn't recognize selecet.

Example:

function dodajKategorijo()
    {
            var ime_kategorije = $('#ime_kategorije').val();
            if(ime_kategorije!= '')
            {
                    $.ajax({
                        type: "GET",
                        url: "<?php echo constant('REL_PATH'); ?>/admin/dodajkategorijo/",
                        dataType: 'json',
                        data:
                        {
                          id: ime_kategorije
                        },
                        success: function(data) {

                            var vsebina = '';
                            vsebina = '<div id="kategorija'+data.id+'" class="form-field clear">'+
                                      '<label for="'+data.ime_kategorije+'" class="form-label size-80 fl-space2">&nbsp;</label>'+
                                      '<input disabled value="'+data.ime_kategorije+'" type="text" id="'+data.id+'" class="required size-140 text fl" name="form[naslov]" />'+
                                      '<a href="javascript:void:(0)" onClick="izbrisiKategorijo('+data.id+')"><img src="<?php echo constant('REL_PATH'); ?>/images/button/delete.png" class="gumbek" alt="" /></a>'
                                      '</div>';

                            $('#nalozene_kategorije').append(vsebina);

                            izbrisiSeznam();
                        }
                    });
                    return true;
                }
                else
                {
                    alert('Vnesti morate ime kategorije');
                    return false;
                }
    }

Answer

Daniel Platon picture Daniel Platon · Jun 27, 2012

To remove all options from your filtering select:

dijit.byId('kat').removeOption(dijit.byId('kat').getOptions());

Worked for me in Dojo 1.7.2