genemu_jqueryselect2_entity doesn't work
maks-rafalko opened this issue · 12 comments
Hi,
symfony: 2.3.2
genemuFormBundle 2.2.0
When I create field with type genemu_jqueryselect2_entity
, it is rendered on the page, but javascript is not invoked. So select element looks like original.
I see in the bundle source such twig block:
{% block genemu_jqueryselect2_javascript %}
<script type="text/javascript">
jQuery(document).ready(function($) {
$field = $('#{{ id }}');
{% block genemu_jqueryselect2_javascript_prototype %}
$field.select2({{ configs|json_encode|raw }});
{% endblock %}
});
</script>
{% endblock %}
- Should it be called automatically?
- I can't understand this point. Or I should run this code manually?
I've also added assets, this setting
genemu_form:
select2: ~
and these blocks to my form template
{% block stylesheets %}
{{ form_stylesheet(form) }}
{% endblock %}
{% block javascripts %}
{{ form_javascript(form) }}
{% endblock %}
My form is rendered by this code:
{{ form(form) }}
Thank you.
Hi mrafalko,
I have the same issue, this bundle seems not working with Symfony 2.3.2 ?!
I opened an issue (Issue #284) regarding the simple autocomplete without using the Jquery select 2 but no one has answered me until now.
I tried both autocompletes (simple one and by using Jquery select 2) but no one is working.
@lynx-net thank you for the comment.
Hi @genemu , we need your help. Please see comments above.
symfony 2.3.2 and genemu-form-bundle 2.2.0 would generate an error (Twig_Error_Runtime exception when using form_javascript ... cf. #281) so you're probably reporting wrong versions here.
I've just tried out with sf 2.3.2 and genemu-form-bundle 2.2.1 and it works fine :
<link rel="stylesheet" href="{{ asset('libs/select2/select2.css') }}" >
{{ form(form) }}
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
<script src="{{ asset('libs/select2/select2.min.js') }}"></script>
{{ form_javascript(form) }}
please provide a symfony standard fork reproducing the issue.
I'm using sf 2.3.2 (Symfony_Standard_Vendors_2.3.2)
I updated the genemu-form-bundle from 2.2.0 to 2.2.1 version:
when I try to use the genemu_jqueryselect2_entity the field still on normal select (not autocomplete form), it seems that jquery is not applied to this field :(
regarding Issue #284: genemu_jqueryautocomplete_entity filed is a simple input text not autocomplete form :(.
Any idea about the missing configuration ?
Thank you.
Works after upgrading to v2.2.1
This code must be in the template (as in the @bamarni 's example).
{{ form_javascript(form) }}
Don't know why documentation says to past this code instead:
{% block javascripts %}
{{ form_javascript(form) }}
{% endblock %}
Hi @mrafalko,
Could you please share your complete example ?, I still not able to make it work :(
I'm using bootstrap as CSS framework, I deactivate it but still not working :(
Thank you.
Hi @lynx-net , sure:
composer.json:
"require": {
...
"genemu/form-bundle": "2.2.*"
...
},
app/config.yml:
...
genemu_form:
select2: ~
...
Form rendering in the page template:
...
{{ form(form) }}
// at the bottom of the file
{{ form_javascript(form) }}
...
You must manually download select2.js/select2.css and images and put them to your Resources/(js|css|img) folders.
Main Layout template:
{% stylesheets 'bundles/search/css/*' filter='cssrewrite' %}
<link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
{% javascripts '@SearchBundle/Resources/public/js/*' %}
<script src="{{ asset_url }}"></script>
{% endjavascripts %}
Form:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->
->add(
'district',
'genemu_jqueryselect2_entity',
[
'class' => 'XXXCoreBundle:District',
'property' => 'name',
'required' => false,
'configs' => [
'placeholder' => 'Select a district',
'width' => 'resolve',
'allowClear' => true,
]
]
);
}
Thanks @mrafalko,
Finally I know why it is not working for me:
I tried with an entity which belongs to the form and it works fine but when I want to use it for an entity which is on an embedded form then it doesn't work :(
Any idea about how can I make it work on an embedded form ?
Thank you.
Thanks @bamarni, hope to have quickly a fixe of this issue
I'm not able to work on it for the moment, if you want to contribute, it'd require editing Resources/views/Form/jquery_layout.html.twig's form_javascript block to iterate recursively instead of one level.
I'd like to contribute but I'm not an expert of Symfony, I'm just a beginner :(