{% load djblets_forms djblets_utils i18n %}

{% block pre_fields %}{% endblock %}
{{form.non_field_errors}}

{% for field in form %}
{%  if field.is_hidden %}
{{field}}
{%  endif %}
{% endfor %}

<div class="fields-row">
 <div class="field">
  {% label_tag form.avatar_service_id %}
  {{form.avatar_service_id}}
 </div>
</div>

{% for service_id, form in form.avatar_service_forms.items %}
<div class="avatar-service-fields" data-avatar-service-id="{{service_id}}">
 {{form.render|safe}}
</div>
{% endfor %}
<script>
$().ready(function() {
    Djblets.Avatars.SettingsFormView.ready.then(function() {
{% for service_id, form in form.avatar_service_forms.items %}
        Djblets.Avatars.SettingsFormView.addConfigForm('{{service_id}}', {{form.js_view_class}});
{% endfor %}
        Djblets.Avatars.SettingsFormView.instance.renderForms();
    });
});
</script>

{% block post_fields %}{% endblock %}

{% if form.save_label %}
<input type="submit" class="btn" value="{{form.save_label}}" />
{% endif %}
