maraujop/django-crispy-forms — pull request #282 by bielfrontera (2014-01-12 15:48:32+00:00)
Title: Dynamic layout: remove field by its field_name instead of index

New two methods at LayoutObject: pop_field(field_name) and remove_layout_object(pointer_index).

Crispy forms documentation says that to remove an object we have to use pop(index) (see http://django-crispy-forms.readthedocs.org/en/d-0/dynamic_layouts.html). But this index is not always easy to get.

Example:

If we have this form (taken from tests):

```python

form = TestForm()
form_helper = FormHelper()
form_helper.add_layout(
Layout(
Fieldset(
u'Company Data',
'is_company',
'email',
'password1',
'password2',
css_id = "multifield_info",
),
Column(
'first_name',
'last_name',
css_id = "column_name",
)
)
)
```

Now we have to use this code to dynamically delete a field (pop or del):
```python
form.fields.pop('email')
form_helper.layout.fields[0].pop(1)
```

And with these new functions, we could do:
```python
form.fields.pop('email')
form_helper.layout.pop_field('email')
```