<commit_before>angular-django-formets
======================

[![Build Status](https://travis-ci.org/hilios/angular-django-formsets.png?branch=master)](https://travis-ci.org/hilios/angular-django-formsets)

A set of AngularJS directives to easily manage Django Formsets into front-end.

## Usage

Add the `djangoFormsets` module to your Angular application:

```
angular.module('myApp', ['djangoFormsets']);
```

Given you have a template with local variable `formset` that is an instance of `BaseFormSet` (usualy created by the factory `formset_factory`):

```html
<form method="post">{% csrf_token %}
  <div django-formset="template.html">
    {{formset.management_form}}
    <div django-formset-container>
      {% for form in formset %}
      <div django-formset-child>
        {{form.as_p}}
        <button django-formset-remove>Remove</button>
      </div>
      {% endfor %}
    </div>
    <button django-formset-add>Add</button>
  </div>
  <button type="submit">Submit</button>
</form>
<!-- template.html -->
{% with form=formset.empty_form %}
<script type="text/ng-template" id="template.html">
<div django-formset-child>
  {{form.as_p}}
  <button django-formset-remove>Remove</button>
</div>
</script>
{% endwith %}
```

## Bult-in directives

```
django-formset="{template}.html"
django-formset-child
django-formset-add
django-formset-remove

# Modifiers
django-formset-prefix
django-formset-can-delete
django-formset-can-order
```

## Python

Given the django formset:

```python
from django import forms
from django.shortcuts import render, redirect
from django.forms.formsets import formset_factory
 
class SimpleForm(forms.Form):
    name = forms.CharField()
    email = forms.EmailField()
 
SimpleFormSet = formset_factory(SimpleForm, extra=2, can_delete=True)

def main(request):
    formset = SimpleFormSet(request.POST or None, prefix="foo")

    if form.is_valid() and formset.is_valid():
        return redirect('/')
 
    return render(request, 'template.html', {'formset': formset})
```<commit_msg>Update the README<commit_after>angular-django-formset
======================

[![Build Status](https://travis-ci.org/hilios/angular-formsets.png?branch=master)](https://travis-ci.org/hilios/angular-formsets)

A set of AngularJS directives to easily manage Django Formsets (add and remove) into front-end.

## Usage

Add the `ngDjangoFormset` module to your Angular application:

```
angular.module('app', ['ngDjangoFormset']);
```

Given you have a template with local variable `formset` that is an instance of `BaseFormSet` (usualy created by the factory `formset_factory`):

```html
<form method="post">{% csrf_token %}
  <div formset="template.html">
    {{formset.management_form}}
    <div formset-container>
      {% for form in formset %}
      <div formset-child>
        {{form.as_p}}
        <button formset-remove>Remove</button>
      </div>
      {% endfor %}
    </div>
    <button formset-add>Add</button>
  </div>
  <button type="submit">Submit</button>
</form>
<!-- template.html -->
{% with form=formset.empty_form %}
<script type="text/ng-template" id="template.html">
<div formset-child>
  {{form.as_p}}
  <button formset-remove>Remove</button>
</div>
</script>
{% endwith %}
```

## Bult-in directives

```
formset="{template}.html"
formset-child
formset-add
formset-remove

# Modifiers
formset-prefix
formset-can-delete
formset-can-order
```

## Python

Given the django formset:

```python
from django import forms
from django.shortcuts import render, redirect
from django.forms.formsets import formset_factory

class SimpleForm(forms.Form):
    name = forms.CharField()
    email = forms.EmailField()

SimpleFormSet = formset_factory(SimpleForm, extra=2, can_delete=True)

def main(request):
    formset = SimpleFormSet(request.POST or None, prefix="foo")

    if form.is_valid() and formset.is_valid():
        return redirect('/')

    return render(request, 'template.html', {'formset': formset})
```
{'fraction_non_alphanumeric': 0.1590678824721378, 'fraction_numerical': 0.0005065856129685917, 'mean_word_length': 4.4170096021947876, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 45, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6729251', 'n_tokens_mistral': 1319, 'n_tokens_neox': 1253, 'n_words': 295}