From ab4d9e174f3b20e6b4160e13cba0f23e09df4929 Mon Sep 17 00:00:00 2001 From: Marc Ducobu Date: Wed, 26 Nov 2014 17:50:08 +0100 Subject: [PATCH] add javascript to ensure that fields with '_other' are checked - close #349 --- Resources/views/Form/fields.html.twig | 3 +-- Resources/views/layout.html.twig | 7 +++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Resources/views/Form/fields.html.twig b/Resources/views/Form/fields.html.twig index 4cdfe4601..79251f765 100644 --- a/Resources/views/Form/fields.html.twig +++ b/Resources/views/Form/fields.html.twig @@ -49,8 +49,7 @@ {{ form_label(child, '', {'label_attr': { 'class' : 'inline'} }) }} {% endfor %} - {{ form_widget(form._choices) }} - {{ form_widget(form._other) }} + {{ form_widget(form._other, {'attr': {'class': 'input-text-other-value'} }) }} {% endspaceless %} {% endblock choice_with_other_widget %} diff --git a/Resources/views/layout.html.twig b/Resources/views/layout.html.twig index 541f1665c..f1830d04d 100644 --- a/Resources/views/layout.html.twig +++ b/Resources/views/layout.html.twig @@ -157,6 +157,13 @@ init_pikaday('{{ app.request.locale }}'); + $('.input-text-other-value').each(function() { + $(this).change(function() { + checkbox = $(this).parent().find("input[type=checkbox][value=_other]")[0]; + $(checkbox).prop('checked', ($(this).val() !== "")) + }); + }); + $('.select2').select2();