jrief / django-angular

Let AngularJS play well with Django
http://django-angular.awesto.com/
MIT License
1.23k stars 294 forks source link

Uncorrect adding of ng attributes for MultiWidget #289

Closed vivazzi closed 6 years ago

vivazzi commented 7 years ago

For example, I want to filter products by price using django-filters:

class FilterForm(NgModelFormMixin, Bootstrap3Form):
    def __init__(self, *args, **kwargs):
        kwargs.update({'scope_prefix': 'filters',
                       'ng_change': 'filterChanged()'})
        super(FilterForm, self).__init__(*args, **kwargs)

class CustomFilterSet(django_filters.FilterSet):
    ...
    unit_price = django_filters.RangeFilter(label='From - To', name='unit_price')

    class Meta:
        model = Product
        form = FilterForm
        fields = ('unit_price', )

    @classmethod
    def get_render_context(cls, request, queryset):
        filter_set = cls(data=request.GET)
        ...
        return dict(filter_set=filter_set)

I get html:

<label for="id_unit_price">From - To</label>
<input class="form-control ng-valid ng-not-empty ng-dirty ng-valid-parse ng-touched" id="id_unit_price_0" name="unit_price_0" ng-change="filterChanged()" ng-model="filters['unit_price']" type="text" style="">
-
<input class="form-control ng-pristine ng-valid ng-not-empty ng-touched" id="id_unit_price_1" name="unit_price_1" ng-change="filterChanged()" ng-model="filters['unit_price']" type="text" style="">

Although, I should get:

<label for="id_unit_price">From - To</label>
<input class="form-control ng-valid ng-not-empty ng-dirty ng-valid-parse ng-touched" id="id_unit_price_0" name="unit_price_0" ng-change="filterChanged()" ng-model="filters['unit_price_0']" type="text" style="">
-
<input class="form-control ng-pristine ng-valid ng-not-empty ng-touched" id="id_unit_price_1" name="unit_price_1" ng-change="filterChanged()" ng-model="filters['unit_price_1']" type="text" style="">

i. e. ng-model instead of ng-model="filters['unit_price']" should be ng-model="filters['unit_price_0']" for first input and ng-model="filters['unit_price_1']" for second input.

adrienbrunet commented 7 years ago

Correct. this is the second time this issue is reported (Issue #288 ) . Support for MultipleValueField may need some more work. Would you like to investigate?

vivazzi commented 7 years ago

@adrienbrunet I am glad to help! I will try it in May (now I'm busy). I will do pull request as soon as I can.

jrief commented 7 years ago

@vivazzi could you please check with version 1.0 after 1.1 will be released.

jrief commented 6 years ago

ping @vivazzi

jrief commented 6 years ago

closing for inactivity