Opened 6 years ago

Closed 6 years ago

#29956 closed New feature (fixed)

Allow formset form widget override for the ORDER field

Reported by: Claude Paroz Owned by: Hasan Ramezani
Component: Forms Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

It would be handy to be able to override the widget of the added ORDER field of a formset form with can_order=True. The typical use case is to use a HiddenInput to manage the formset ordering in the UI without a visible form field.
At first sight, I think this could be easily doable in the BaseFormSet.add_fields method.

Change History (13)

comment:1 by Tim Graham, 6 years ago

Triage Stage: UnreviewedAccepted

comment:2 by Hasan Ramezani, 6 years ago

Has patch: set
Owner: changed from nobody to Hasan Ramezani
Status: newassigned
Last edited 6 years ago by Tim Graham (previous) (diff)

comment:3 by Hasan Ramezani, 6 years ago

Here is the summary of conversation between me and @claudep on the PR :

I did this feature by adding the order_field_widget to formset_factory functions. (now available in the PR)

@claudep suggested managing this by adding a key in widgets property of ModelForm. something like this:

class AuthorForm(ModelForm):
    class Meta:
        model = Author
        fields = ('name', 'title', 'birth_date')
        widgets = {
            'ORDER': HiddenInput(),
        }

It works for ModelForm because we can access the widgets property of ModelForm by : model_form._meta.widgets.
But it is possible to have this feature for formset which generated by the normal forms, because the normal form that inherits from forms.Form has not the widgets property.

So @claudep suggest to first add this feature just for ModelForm.

what is the final decision?

comment:4 by Tim Graham, 6 years ago

Patch needs improvement: set

comment:5 by Hasan Ramezani, 6 years ago

Patch needs improvement: unset

I change my PR and manage the widget based on ORDER key in widgets dictionary. and this feature just works for ModelForm now.

comment:6 by Carlton Gibson, 6 years ago

Patch needs improvement: set
Version: 2.1master

On the PR I've suggested a third-option (rather than adding an argument to formset_factory() or using the ModelForm's Meta.widgets ) to have users subclass BaseFormSet in this case and pass that as the formset argument to formset_factory().

This keeps the logic in with the formsets but does not expand the signature of formset_factory(), which is already long enough.

comment:7 by Hasan Ramezani, 6 years ago

Patch needs improvement: unset

I changed the PR based on your suggestion. please check it and let me know if something else is required.

comment:8 by Carlton Gibson, 6 years ago

Patch needs improvement: set

Small tweaks needed then good to go I think.

comment:9 by Hasan Ramezani, 6 years ago

Patch needs improvement: unset

comment:10 by Hasan Ramezani, 6 years ago

Requested changes are Done.

comment:11 by Carlton Gibson, 6 years ago

Needs documentation: set

As per PR, the docs here just need a small amount of work and then this is looking good to go.

comment:12 by Hasan Ramezani, 6 years ago

Needs documentation: unset

Docs fixed as your request.

comment:13 by Mariusz Felisiak <felisiak.mariusz@…>, 6 years ago

Resolution: fixed
Status: assignedclosed

In 5fc5d935:

Fixed #29956 -- Allowed overriding an order field widget in formsets.

Note: See TracTickets for help on using tickets.
Back to Top