私の VMachine フォームには、2 つのフィールド (エンティティ) データストアとクラスターがあり、各クラスターは多くのデータストアをホストしています。そのため、選択したクラスターに応じてデータストアのリストを動的に表示したいと考えています。
エンティティ データストアには、フィルタリングを適用できる適切なクラスターの ID が含まれています。
問題は、現在選択されているアイテムの値を取得して、データストアのリストをフィルター処理できないことです: ここに私のフォーム ビュー コードがあります:
<form action="{{ path('vm_create') }}" method="post" {{ form_enctype(form) }}>
{{ form_errors(form) }}
<div>
{{ form_label(form.cluster) }}
{{ form_errors(form.cluster) }}
{{ form_widget(form.cluster) }}
</div>
<div>
{# the list of all datastores is passed on parameters to the form view from the
controller #}
{% block datastore_widget%}
{% spaceless %}
<select {{ block('widget_attributes') }}>
{% for datastore in datastores %}
{{ form.vars.value.cluster }}
{% if datastore.cluster.id == form.vars.value.cluster %}
<option value="{{ datastore.nom }}">{{ datastore.nom }}</option>
{% endif %}
{% endfor %}
</select>
{% endspaceless %}
{% endblock datastore_widget%}
</div>
form.vars.value.cluster が、選択されたクラスターの現在の値を取得していないようです!