Skip to content

Instantly share code, notes, and snippets.

@Dubiy
Created February 16, 2016 08:43
Show Gist options
  • Save Dubiy/449bf6b1285dfeb4fcbf to your computer and use it in GitHub Desktop.
Save Dubiy/449bf6b1285dfeb4fcbf to your computer and use it in GitHub Desktop.
Symfony2 form override to work with AngulaJS
{%- block form_start -%}
{% set method = method|upper %}
{%- if method in ["GET", "POST"] -%}
{% set form_method = method %}
{%- else -%}
{% set form_method = "POST" %}
{%- endif -%}
<form name="{{ name }}" method="{{ form_method|lower }}" action="{{ action }}"{% for attrname, attrvalue in attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}{% if multipart %} enctype="multipart/form-data"{% endif %}>
{%- if form_method != method -%}
<input type="hidden" name="_method" value="{{ method }}" />
{%- endif -%}
{%- endblock form_start -%}
{%- block widget_attributes -%}
ng-init="{{ name }} = '{{ value| replace({"'":"\\'", "\\":"\\\\" })|e('html_attr') }}'"
ng-model="{{ name }}"
id="{{ id }}" name="{{ full_name }}"
{%- if disabled %} disabled="disabled"{% endif -%}
{%- if required %} required="required"{% endif -%}
{%- for attrname, attrvalue in attr -%}
{{- " " -}}
{%- if attrname in ['placeholder', 'title'] -%}
{{- attrname }}="{{ translation_domain is same as(false) ? attrvalue : attrvalue|trans({}, translation_domain) }}"
{%- elseif attrvalue is same as(true) -%}
{{- attrname }}="{{ attrname }}"
{%- elseif attrvalue is not same as(false) -%}
{{- attrname }}="{{ attrvalue }}"
{%- endif -%}
{%- endfor -%}
{%- endblock widget_attributes -%}
{% block form_row %}
<div class="form_row">
{{ form_label(form) }}
{{ form_widget(form) }}
{{ form_errors(form) }}
</div>
{% endblock form_row %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment