{% load l10n %}
<script type="text/javascript">
(function($) {
    var field;

{% for field in prepopulated_fields %}
    field = {
        id: '#{{ field.field.auto_id }}',
        dependency_ids: [],
        dependency_list: [],
        maxLength: {{ field.field.field.max_length|default:"50"|unlocalize }},
        allowUnicode: {{ field.field.field.allow_unicode|default:"false"|lower }}
    };

    {% for dependency in field.dependencies %}
    field['dependency_ids'].push('#{{ dependency.auto_id }}');
    field['dependency_list'].push('{{ dependency.name }}');
    {% endfor %}

    {% comment %}
    Mark prepopulated fields in the main form and stacked inlines (.empty-form .form-row) and in tabular inlines (.empty-form.form-row)
    {% endcomment %}
    $('.empty-form .form-row .field-{{ field.field.name }}, .empty-form.form-row .field-{{ field.field.name }}').addClass('prepopulated_field');
    $(field.id).data('dependency_list', field['dependency_list'])
               .prepopulate(field['dependency_ids'], field.maxLength, field.allowUnicode);
{% endfor %}
})(django.jQuery);
</script>
