I want to convert a string value to day by tapping in a widget, e.g. 24 → 1
{% block convert_day %}
<td>{{ form_widget(form['crush']) }}</td>
<td><!-- displaying my value in day --></td>
{% endblock %}
No It doesn't work !
To be more clear ,I want to do something like that but just display number of days : http://www.convertworld.com/en/time/Days.html
{{ hourValue / 24 }}
Or, if you want to round the value to two decimal places:
{{ hourValue / 24 | number_format(2, ".", ",") }}
Documentation:
http://twig.sensiolabs.org/doc/templates.html#math
http://twig.sensiolabs.org/doc/filters/number_format.html
edit
Alternatively, you can put the precision into the form instance itself. When you create your form, you're probably doing something like this in your controller (or if the form has its own class, you're doing something similar in the buildForm() method of that class):
$form = $this->createFormBuilder($entity)
->add('name', 'text')
->getForm();
When you add your crush field, you can then specify the number of decimal places that should be represented on the form by including the precision option:
$form = $this->createFormBuilder($entity)
->add('name', 'text')
->add('crush', 'number', array('precision' => 3) )
->getForm();
The form will then round the value before inserting it into the database.
Documentation:
http://symfony.com/doc/current/reference/forms/types/number.html#precision
that's what I did ;
<script type="text/javascript">
function execute_time_ext(clicked) {
if (document.forms && document.forms['show_convert']) {
var from = document.forms['show_convert'].unit_from.value;
var elms = document.getElementsByName('unit');
var amount = document.forms['show_convert']['value'].value;
var to;
var amount_int = ['show_convert']['value'] - 0;
for (var i=0; i<elms.length; i++) {
to = elms[i].value;
convert(show_convert['value'], from, to, false, false);
}
var cookie = 'default_decimals';
if (getCookie(cookie) != decimals) {
setCookie(cookie, decimals, null, '/');
}
} else {
if (clicked) {
alert('Converter error. Conversion not supported by browser.');
}
}
}
execute_time_ext(false);
</script>
widget :
<div onkeyup="execute_time_ext(true)" onchange="execute_time_ext(true)"> {{ form_widget(form['value']) }} {% endblock %}
<div> <input id="value_4" type="hidden" value="365.25|0|4" name="unit"></div>
</div>
Related
Hello guys,
On Symfony 3 :
I tried to follow the requirements of "How to Embed a Collection of Forms" from Symfony 3 Documentation. It works for a defined list as they propose first. But when I try the next step: Allowing new Tags with the Prototype, it only returns my last embed Form.
So I know that my Entity works, aswell as the EntityType. The error must be on the Twig.
Thanks in advance for your help!
It works for a defined list as they propose in the first part.
So I know that my Entity works, aswell as the EntityType.
enter code here
{% extends "#App/baseAdmin.html.twig" %} .
{% block contenu %} .
{#{{ dump(formreservation) }}#} .
{#{{ form(formreservation) }}#} .
<div> .
Date : {{ "now"|date("d/m/Y") }} .
{{ form_start(formreservation, {'attr': {'class': 'form'}}) }} .
{#{{ dump(formreservation) }}#} .
<p> .
{#retourne message erreur si besoin après méthode isValid dans Controleur#} .
{{ form_errors(formreservation.spectacle) }} .
{{ form_label(formreservation.spectacle, null,
{'label_attr': {'class': 'form-label'}}) }} :
{{ form_widget(formreservation.spectacle, {'attr':
{'class': 'form-control'}}) }} .
</p>
<p>
{{ form_label(formreservation.spectateur, null,
{'label_attr': {'class': 'form-label'}}) }}
<ul class="spectateur" data-prototype="{{ form_widget(formreservation.spectateur.vars.prototype)|e('html_attr') }}">
</ul>
</p>
<p>
{#retourne message erreur si besoin après méthode isValid dans Controleur#}
{{ form_errors(formreservation.client) }}
{{ form_label(formreservation.client, null,
{'label_attr': {'class': 'form-label'}}) }} :
{{ form_widget(formreservation.client, {'attr':
{'class': 'form-control'}}) }}
</p>
{# génération du champ CSRF - _token# (Cross Site Request Forgeries en champ caché #}
{{ form_rest(formreservation) }}
{{ form_end(formreservation) }}
</div>
{# Partie JavaScript #}
<script
src="https://code.jquery.com/jquery-3.3.1.js"
integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60="
crossorigin="anonymous">
</script>
<script>
var $collectionHolder;
// setup an "add a tag" link
var $addTagButton = $('<button type="button" class="add_tag_link">Ajoutez un spectateur</button>');
var $newLinkLi = $('<li></li>').append($addTagButton);
jQuery(document).ready(function() {
// Get the ul that holds the collection of tags
var $collectionHolder = $('ul.spectateur');
// add a delete link to all of the existing tag form li elements
//inutile pour le moment, ajoute un bouton qui créé la confusion
/* $collectionHolder.find('li').each(function() {
addTagFormDeleteLink($(this));
});*/
// add the "add a tag" anchor and li to the tags ul
$collectionHolder.append($newLinkLi);
// count the current form inputs we have (e.g. 2), use that as the new
// index when inserting a new item (e.g. 2)
$collectionHolder.data('index', $collectionHolder.find(':input').length);
$addTagButton.on('click', function(e) {
// add a new tag form (see next code block)
e.preventDefault();
addTagForm($collectionHolder, $newLinkLi);
});
});
function addTagForm($collectionHolder, $newLinkLi) {
// Get the data-prototype explained earlier
//console.log($collectionHolder);
var prototype = $collectionHolder.data('prototype');
//console
// get the new index
var index = $collectionHolder.data('index');
var newForm = prototype;
// You need this only if you didn't set 'label' => false in your tags field in TaskType
// Replace '__name__label__' in the prototype's HTML to
// instead be a number based on how many items we have
newForm = newForm.replace(/__name__label__/g, 'Spectateur n° '+ index);
//newForm = newForm.replace(/__name__/g, index);
// increase the index with one for the next item
$collectionHolder.data('index', index + 1 );
// Display the form in the page in an li, before the "Add a tag" link li
var $newFormLi = $('<li></li>').append(newForm);
$newLinkLi.before($newFormLi);
// add a delete link to the new form
addTagFormDeleteLink($newFormLi);
}
function addTagFormDeleteLink($tagFormLi) {
var $removeFormButton = $('<button type="button">enlever ce spectateur</button><br>');
$tagFormLi.append($removeFormButton);
$removeFormButton.on('click', function(e) {
// remove the li for the tag form
e.preventDefault();
$tagFormLi.remove();
});
}
</script>
{% endblock %}
Expected result : a collection containing all the embed Forms.
Actually it only returns the last element in the embed Form. I did check on the Entity and it doesn't use the "add" method that I did add to the entity.
here the add part of ReservationType builder:
->add('spectateurs', CollectionType::class, [
'entry_type' => SpectateurReservationType::class,
'entry_options' => ['label' => false],
'allow_add' => true,
'allow_delete' => true,
'prototype' => true,
'by_reference' => false,
] .
) .
)
You just have commented a part of JS code
newForm = newForm.replace(/__name__/g, index);
Uncomment this and anything would be nice
my line was:
newForm = newForm.replace(/name__label/g, 'Spectateur n° '+ index);
My mistake was, I thought I could change this as a textlabel:
Great it only was this! many thanks, you save me! Now it works perfectly!
I want to display a user picture (avatar) and some more fields in the menu.html.twig template.
I know that we can display these fields in a user.html.twig template.
{{ content.user_picture }}
{{ user.getDisplayName() }}
{{ content.field_name_user[0] }}
and etc.
But I want to display these fields in the menu.html.twig template.
As I think. we can make a variable in preprocess_block () and print the desired value.
Or if there is no necessary variable in the template - do it in the preprocessor of this template!
Help please make a decision on this issue. And what code you need to write.
It is better to write a pre-process and define a variable and insert the desired elements in it.
hook_preprocess_menu__menu_name(array &$variables) {
$userDetails = \Drupal\user\Entity\User::load(\Drupal::currentUser()->id());
/**
fetch the desired elements and pass to $variables eg:
**/
$variables['userPictureUrl'] = $userDetails->user_picture->entity->url();
}
You can use hook_preprocess_menu:
function YOURMODULE_preprocess_menu(&$variables)
{
$uid = \Drupal::currentUser()->id();
if($uid > 0)
{
// Load user
$user = User::load($uid);
$userName = $user->getUsername();
// If user have a picture, add it to variable
if(!$user->user_picture->isEmpty()){
$pictureUri = $user->user_picture->entity->getFileUri();
// Add style to picture
$userPicture = [
'#theme' => 'image_style',
'#style_name' => 'profile_picture',
'#uri' => $pictureUri,
];
}
// Set variables
$variables['MYMODULE'] = [
'profile_name' => $userName,
'profile_picture' => $userPicture,
'profile_id' => $userId
];
}
}
End show in your menu.html.twig file:
{{ YOURMODULE.profile_name }}
{{ YOURMODULE.profile_picture }}
{{ YOURMODULE.profile_id }}
what i need
i need to show the currency code .
like usd : $.
i have used script
<script type="text/javascript">
var cod=new Array();
var sym=new Array();
cod[0]='ALL';sym[0]='Lek';cod[1]='USD';sym[1]='$';cod[2]='AFN';sym[2]='؋';cod[3]='ARS ';sym[3]='$';cod[4]='AWG';sym[4]='ƒ';cod[5]='AUD';sym[5]='$';cod[6]='AZN';sym[6]='ман';cod[7]='BSD;';sym[7]='$';cod[8]='BBD';sym[8]='$';cod[9]='BYR';sym[9]='p.';cod[10]='BEF';sym[10]='₣';cod[11]='BZD';sym[11]='BZ$';cod[12]='BMD';sym[12]='$';cod[13]='BOB';sym[13]='$b';cod[14]='BAM';sym[14]='KM';cod[15]='BWP ';sym[15]='P';cod[16]='BGN';sym[16]='лв';cod[17]='BRL';sym[17]='R$';cod[18]='BRC';sym[18]='₢';cod[19]='GBP';sym[19]='£';cod[20]='BND';sym[20]='$';cod[21]='KHR';sym[21]='៛';cod[22]='CAD ';sym[22]='$';cod[23]='KYD';sym[23]='$';cod[24]='CLP';sym[24]='$';cod[25]='CNY';sym[25]='元';cod[26]='COP ';sym[26]='$';cod[27]='CRC ';sym[27]='₡';cod[28]='HRK';sym[28]='kn';cod[29]='CUP';sym[29]='₱';cod[30]='CYP';sym[30]='£';cod[31]='CZK ';sym[31]='Kč';cod[32]='DKK ';sym[32]='kr';cod[33]='DOP';sym[33]='RD$';cod[34]='XCD ';sym[34]='$';cod[35]='EGP';sym[35]='£';cod[36]='SVC ';sym[36]='$';cod[37]='GBP ';sym[37]='£';cod[38]='EEK';sym[38]='kr';cod[39]='EUR';sym[39]='€';cod[40]='XEU ';sym[40]='₠';cod[41]='FKP';sym[41]='£';cod[42]='FJD';sym[42]='$';cod[43]='FRF';sym[43]='₣';cod[44]='GHC';sym[44]='¢';cod[45]='GIP ';sym[45]='£';cod[46]='GRD ';sym[46]='₯';cod[47]='GTQ';sym[47]='Q';cod[48]='GGP';sym[48]='£';cod[49]='GYD';sym[49]='$';cod[50]='NLG ';sym[50]='ƒ';cod[51]='HNL';sym[51]='L';cod[52]='HKD';sym[52]='HK$';cod[53]='HKD ';sym[53]='圓';cod[54]='HKD ';sym[54]='圓';cod[55]='HKD ';sym[55]='元';cod[56]='HUF';sym[56]='Ft';cod[57]='ISK';sym[57]='kr';cod[58]='INR ';sym[58]='Rs';cod[59]='IDR ';sym[59]='Rp';cod[60]='IRR';sym[60]='﷼';cod[61]='IEP ';sym[61]='£';cod[62]='IMP';sym[62]='£';cod[63]='ILS';sym[63]='₪';cod[64]='ITL';sym[64]='₤';cod[65]='JMD';sym[65]='J$';cod[66]='JPY ';sym[66]='¥';cod[67]='JEP ';sym[67]='£';cod[68]='KZT ';sym[68]='лв';cod[69]='KPW ';sym[69]='₩';cod[70]='KRW ';sym[70]='₩';cod[71]='KGS ';sym[71]='лв';cod[72]='LAK ';sym[72]='₭';cod[73]='LVL ';sym[73]='Ls';cod[74]='LBP ';sym[74]='£';cod[75]='LRD ';sym[75]='$';cod[76]='CHF ';sym[76]='CHF';cod[77]='LTL ';sym[77]='Lt';cod[78]='LUF ';sym[78]='₣';cod[79]='MKD ';sym[79]='ден';cod[80]='MYR ';sym[80]='RM';cod[81]='MTL ';sym[81]='Lm';cod[82]='MUR ';sym[82]='₨';cod[83]='MXN ';sym[83]='$';cod[84]='MNT ';sym[84]='₮';cod[85]='MZN ';sym[85]='MT';cod[86]='NAD ';sym[86]='$';cod[87]='NPR ';sym[87]='₨';cod[88]='ANG ';sym[88]='ƒ';cod[89]='NLG ';sym[89]='ƒ';cod[90]='NZD ';sym[90]='$';cod[91]='NIO ';sym[91]='C$';cod[92]='NGN ';sym[92]='₦';cod[93]='KPW ';sym[93]='₩';cod[94]='NOK ';sym[94]='kr';cod[95]='OMR ';sym[95]='﷼';cod[96]='PKR ';sym[96]='₨';cod[97]='PAB ';sym[97]='B/.';cod[98]='PYG ';sym[98]='Gs';cod[99]='PEN ';sym[99]='S/.';cod[100]='PHP ';sym[100]='Php';cod[101]='PLN ';sym[101]='zł';cod[102]='QAR ';sym[102]='﷼';cod[103]='RON ';sym[103]='lei';cod[104]='RUB ';sym[104]='руб';cod[105]='SHP ';sym[105]='£';cod[106]='SAR ';sym[106]='﷼';cod[107]='RSD ';sym[107]='Дин.';cod[108]='SCR ';sym[108]='₨';cod[109]='SGD ';sym[109]='$';cod[110]='SKK ';sym[110]='SIT';cod[111]='EUR ';sym[111]='€';cod[112]='SBD ';sym[112]='$';cod[113]='SOS ';sym[113]='S';cod[114]='ZAR ';sym[114]='R';cod[115]='KRW ';sym[115]='₩';cod[116]='ESP ';sym[116]='₧';cod[117]='LKR ';sym[117]='₨';cod[118]='SEK ';sym[118]='kr';cod[119]='CHF ';sym[119]='CHF';cod[120]='SRD ';sym[120]='$';cod[121]='SYP ';sym[121]='£';cod[122]='TWD ';sym[122]='NT$';cod[123]='THB';sym[123]='฿';cod[124]='TTD';sym[124]='TT$';cod[125]='TRY';sym[125]='YTL';cod[126]='TRL';sym[126]='₤';cod[127]='TVD ';sym[127]='$';cod[128]='UAH ';sym[128]='₴';cod[129]='GBP ';sym[129]='£';cod[130]='USD ';sym[130]='$';cod[131]='UYU ';sym[131]='$U';cod[132]='UZS ';sym[132]='лв';cod[133]='VAL ';sym[133]='₤';cod[134]='VEB ';sym[134]='Bs';cod[135]='VND ';sym[135]='₫';cod[136]='YER ';sym[136]='﷼';cod[137]='ZWD ';sym[137]='Z';
function list(index)
{
var con=document.getElementById('sym');
if(index==-1)
{
con.innerHTML="";
return;
}
con.innerHTML=sym[index];
}
</script>
<script type="text/javascript">
count=cod.length;
for(i=0;i<count;i++)
document.write("<option value="+i+">"+cod[i]+"</option>");
</script>
</select>
Twig code
{% set currency= '' %}
{% for key,value in temp %}
{% set currency= value %}
<td width="12%" id ="cod" class="aligncenter">{{ value.amount }}<p class=sym>{{ currency}}</p> </td>
i need like 20 $.
i need to convert currency convert through java script.
i have tried but its not laoding in twig file.
If you have list of currency codes you can just go through them and call:
public function getCurrenciesAction()
{
$currencies = array('EUR', 'USD'); //here you need to retrieve your currencies list
$symbols = array();
foreach ($currencies as $currency) {
$symbols[$currency] = $symbol = Intl::getCurrencyBundle()->getCurrencySymbol($currency);
}
return new JsonResponse($symbols);
}
You can then generate JSON array from the whole list and retrieve it in JavaScript via AJAX request.
There is an issue with "document.getElementById('sym');", as there aren't any "sym" element
Change :
<p class=sym>
to
<p id="sym">
I have this function in the controller, that returns a form with a select box. When the values are selected, I retrieve them with
$manifestations = $form['manifestations']->getData();
then put them in a repository function that queries the database $invites = $repository->searchInviteByManif($manifestations);
public function indexAction() {
$entity = new Invite();
$form = $this->createForm(new ManifSearchType(), $entity);
$request = $this->get('request');
$invites = null;
if ($request->getMethod() == 'POST') {
$form->handleRequest($request);
$message = '';
$manifestations = $form['manifestations']->getData();
$repository = $this->getDoctrine()
->getManager()
->getRepository('PrifProtocoleBundle:Invite');
$invites = $repository->searchInviteByManif($manifestations);
$response1 = $this->render('PrifProtocoleBundle:Invite:index.html.twig', array(
'form' => $form->createView(),
'entities' => $invites,
'message' => $message,
));
return $response1;
}
return array(
'form' => $form->createView(),
'entities' => $invites,
);
}
This function then returns a view index.html.twig with a table and all the fields found in the db.
What I want is to export all the queried data $invites in a CSV file, by clicking on a link directly from the HTML table.
So I've put an href="" link in the Twig file,
{% if message is defined %}
<div class="pdf">
<img height="40px" width="40px" src={{ asset('bundles/prifprotocole/images/excel.jpg') }}>
{% for entity in entities %}
<tr class="{{ cycle(['odd', 'even'], loop.index0) }}">
<td>{% if entity.etat == 1 %} Actif {% else %} Inactif {% endif %}</td>
<td>{{ entity.titreGrade }} {{ entity.prenom }} {{ entity.nom }}</td>
<td>{{ entity.fonction }}</td>
This is how I use to export the CSV file without the link :
$response2 = $this->render('PrifProtocoleBundle:Invite:export.csv.twig', array(
'entities' => $invites));
$response2->headers->set('Content-Type', 'text/csv');
$csvfile = $response2->headers->set('Content-Disposition', 'attachment; filename="export.csv"');
return $csvfile;
export.csv.twig file
{% for entity in entities %}
Id {{ entity.id }};
Etat {{ entity.etat }};
Titregrade {{ entity.titreGrade }};
Prenom {{ entity.prenom }};
Nom {{ entity.nom }};
Fonction {{ entity.fonction }};
{% endfor %}
Can someone give me a detailed solution on how to perform this? Much thanks!
You should simply pass the filter criterias, here the $manifestations array as a route parameter, by serializing it first.
Then, you should put a controller like downloadCsvAction() handling this route, querying the $invites from the database, and rendering your export.csv.twig template.
Another option, if you cannot serialize the data in URI, is to create a form with hidden fields containing the data. Then you replace the download link with the submit button of this hidden form.
Guillaume's answer is great if you don't mind fetching your data twice. Once when you display your page, and then when you download the CSV. Another way to do this is to cache the answer. I will give an example using memcache (which is what I use).
First, make sure that memcache is active in your php.ini.
Then before rendering your first page (after fetching the data), cache it:
$key = "csv.$userId";
$memcache = new \Memcache();
$memcache->connect($yourServerHost, $yourServerPort);
$memcache->set($key, json_encode($invites), MEMCACHE_COMPRESSED, 86400); // 24h
The trick is to find a good key, to add your report to the cache, and then be able to retrieve it. It has to be unique. Here, I assume that you have a user that is logged in, and I use the user ID to create a key. If that is not the case, you could create yourself a token, and pass it when rendering the page (along with $invites). This way, you can add the token to the URL to generate the CSV.
Then, in your second action, where you download the CSV, you just fetch the cached data:
$memcache = new \Memcache();
$memcache->connect($yourServerHost, $yourServerPort);
$json = $memcache->get($key);
$invites = json_decode($json , true);
That's it. You should probably create yourself a service for Memcache, so you don't have to create an object, and connect everytime.
I'm trying to create a form which will add a new text box every time the 'Add new box' link got clicked.
I read through the following example.
http://symfony.com/doc/current/reference/forms/types/collection.html
Basically I was following the example from the book. But when the page is rendered and I click on the link nothing happens.
Any thoughts?
Thanks.
This is my controller.
public function createAction() {
$formBuilder = $this->createFormBuilder();
$formBuilder->add('emails', 'collection', array(
// each item in the array will be an "email" field
'type' => 'email',
'prototype' => true,
'allow_add' => true,
// these options are passed to each "email" type
'options' => array(
'required' => false,
'attr' => array('class' => 'email-box')
),
));
$form = $formBuilder->getForm();
return $this->render('AcmeRecordBundle:Form:create.html.twig', array(
'form' => $form->createView(),
));
}
This is the view.
<form action="..." method="POST" {{ form_enctype(form) }}>
{# store the prototype on the data-prototype attribute #}
<ul id="email-fields-list" data-prototype="{{ form_widget(form.emails.get('prototype')) | e }}">
{% for emailField in form.emails %}
<li>
{{ form_errors(emailField) }}
{{ form_widget(emailField) }}
</li>
{% endfor %}
</ul>
Add another email
</form>
<script type="text/javascript">
// keep track of how many email fields have been rendered
var emailCount = '{{ form.emails | length }}';
jQuery(document).ready(function() {
jQuery('#add-another-email').click(function() {
var emailList = jQuery('#email-fields-list');
// grab the prototype template
var newWidget = emailList.attr('data-prototype');
// replace the "$$name$$" used in the id and name of the prototype
// with a number that's unique to our emails
// end name attribute looks like name="contact[emails][2]"
newWidget = newWidget.replace(/\$\$name\$\$/g, emailCount);
emailCount++;
// create a new list element and add it to our list
var newLi = jQuery('<li></li>').html(newWidget);
newLi.appendTo(jQuery('#email-fields-list'));
return false;
});
})
</script>
This problem can be solved by referring to the following link.
https://github.com/beberlei/AcmePizzaBundle
Here you will find the same functionality being implemented.
I've been through this too.
Answer and examples given to this question and the other question I found did not answer my problem either.
Here is how I did it, in some generic manner.
In generic, I mean, Any collection that I add to the form just need to follow the Form template loop (in a macro, for example) and that's all!
Using which convention
HTML is from Twitter Bootstrap 2.0.x
Javascript code is already in a $(document).ready();
Following Symfony 2.0.x tutorial
Using MopaBootstrapBundle
Form Type class
class OrderForm extends AbstractType
{
// ...
public function buildForm(FormBuilder $builder, array $options)
{
// ...
$builder
->add('sharingusers', 'collection', array(
'type' => new UserForm(),
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false,
'required'=> false
));
// ...
}
}
JavaScript
/* In the functions section out of document ready */
/**
* Add a new row in a form Collection
*
* Difference from source is that I use Bootstrap convention
* to get the part we are interrested in, the input tag itself and not
* create a new .collection-field block inside the original.
*
* Source: http://symfony.com/doc/current/cookbook/form/form_collections.html
*/
function addTagForm(collectionHolder, newBtn) {
var prototype = collectionHolder.attr('data-prototype');
var p = prototype.replace(/\$\$name\$\$/g, collectionHolder.children().length);
var newFormFromPrototype = $(p);
var buildup = newFormFromPrototype.find(".controls input");
var collectionField = $('<div class="collection-field"></div>').append(buildup);
newBtn.before(collectionField);
}
/* ********** */
$(document).ready(function(){
/* other initializations */
/**
* Form collection behavior
*
* Inspired, but refactored to be re-usable from Source defined below
*
* Source: http://symfony.com/doc/current/cookbook/form/form_collections.html
*/
var formCollectionObj = $('form .behavior-collection');
if(formCollectionObj.length >= 1){
console.log('run.js: document ready "form .behavior-collection" applied on '+formCollectionObj.length+' elements');
var addTagLink = $('<i class="icon-plus-sign"></i> Add');
var newBtn = $('<div class="collection-add"></div>').append(addTagLink);
formCollectionObj.append(newBtn);
addTagLink.on('click', function(e) {
e.preventDefault();
addTagForm(formCollectionObj, newBtn);
});
}
/* other initializations */
});
The form template
Trick here is that I would have had used the original {{ form_widget(form }} but I needed to add some specific to the view form and I could not make it shorter.
And I tried to edit only the targeted field and found out it was a bit complex
Here is how I did it:
{# All form elements prior to the targeted field #}
<div class="control-collection control-group">
<label class="control-label">{{ form_label(form.sharingusers) }}</label>
<div class="controls behavior-collection" data-prototype="{{ form_widget(form.sharingusers.get('prototype'))|escape }}">
{% for user in form.sharingusers %}
{{ form_row(user) }}
{% endfor %}
</div>
</div>
{{ form_rest(form) }}