jazzband / django-smart-selects

chained and grouped selects for django forms
https://django-smart-selects.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
1.12k stars 352 forks source link

empty_label do not work on ChainedForeignKey #236

Closed mpena2099 closed 4 years ago

mpena2099 commented 6 years ago

Checklist

Put an x in the bracket when you have completed each task, like this: [x]

Steps to reproduce

  1. models.py
class BuscaVeiculo(models.Model):
    marca = models.ForeignKey(Marca, blank = True, null=True)
    modelo = ChainedForeignKey(
        Modelo,
        chained_field="marca",
        chained_model_field="marca",
        show_all=False,
        auto_choose=True,
        verbose_name='Modelo',
        blank = True,
        null = True,
    )
  1. forms.py
class FiltraVeiculoForm(forms.ModelForm):
    ano = forms.ChoiceField(choices=year_dropdown, widget=forms.Select(attrs={'class': 'form-control'}))

    class Meta:
        model = BuscaVeiculo
        fields = ('marca', 'modelo',)
        widgets = {
                    'marca': forms.Select(attrs={'class': 'form-control'}),
                    'ano': forms.Select(attrs={'class': 'form-control'}),
        }

    def __init__(self, *args, **kwargs):
        super(FiltraVeiculoForm, self).__init__(*args, **kwargs)
        self.fields['marca'].empty_label = "Filtrar por marca"      # <------ WORKS!
        self.fields['modelo'].empty_label = "Filtrar por modelo"  # <------ DO NOT WORK!

Actual behavior

Setting the empty_label do not work on ChainedForeignKey.

Thanks! Mauricio

blag commented 6 years ago

When you say it doesn't work, what do you mean? Is the empty label not what you expect? What label do you expect? What label shows up?

mpena2099 commented 6 years ago

@blag , thanks for your reply.

You can see what I mean in http://www.autofive.com.br/veiculos/ . I do not know how to change de label "--------" on the second select field in that page.

Thanks! Mauricio

albixhafa commented 4 years ago

self.fields['category'].empty_label = 'SELECT CATEGORY' <--- works self.fields['subcategory'].empty_label = 'SELECT CATEGORY' <--- Does not work

any solutions to this?

manelclos commented 4 years ago

@mpena2099 can you reproduce with latest master version?

manelclos commented 4 years ago

Closing due to inactivity

urzbs commented 1 month ago

this is still not working. latest master.