Allow spaces when using Select2 tags symfony - symfony

I try to create tags if not exist by using select2 entity. When I try to add a tag that contains spaces I can't.
For example :
"Yupi yola" --> not work because tag contains spaces, is getting only first word "Yupi".
"Test" ---> work
"Test_test" ---> work
I added the Select2Entity in my form type
->add('groupe', Select2EntityType::class, [
'remote_route' => 'route',
'class' => Class::class,
'primary_key' => 'id',
'text_property' => 'name',
'minimum_input_length' => 2,
'page_limit' => 10,
'allow_clear' => true,
'delay' => 250,
'cache' => true,
'cache_timeout' => 60000, // if 'cache' is true
'language' => 'en',
'placeholder' => 'Select a group',
'allow_add' => array(
'enabled' => true,
'new_tag_text' => '',
'tokenSeparators'=> '[",", " "]'
),
'multiple' => false,
'attr' => ['style' => 'width:100%'],
'scroll' => true,
])
Please help me. Thx in advance.

Instead of 'tokenSeparators', use 'tag_separators'
'allow_add' => array(
'enabled' => true,
'new_tag_text' => '',
'new_tag_prefix' => '__',
'tag_separators'=> '[",", " "]'
)

Related

entitytype multiple default value

i have a entitytype and i want give default value (i have the id of entity type)
->add('esame_' . $i, EntityType::class, array(
'label' => false,
'mapped' => false,
'class' => 'AppBundle:Nome_esame',
'required' => true,
'multiple' => true,
'data'=>array($id_Nome_esame1,$id_Nome_esame2) ,
'choice_label' => 'nome',
// 'disabled' => 'disabled',
'attr' => array(
'placeholder' => 'Esami',
'class' => 'max_width esame_row select_esame',
// 'class'=>'col-md-12 col-md-offset-0 col-xs-9 col-xs-offset-3 ',
)
))
My goal is give 2 or more default value to that entity
i try
'data'=>array($id_Nome_esame1,$id_Nome_esame2)
where $id_Nome_esame1, and $id_Nome_esame2 are the id value of entity type by it don't work
I think your data has to be the same type as the class (AppBundle:Nome_esame)
Try something like this (you will need to bring doctrine or the entity manager into your FormType if you didn't do that yet)
->add('esame_' . $i, EntityType::class, array(
'label' => false,
'mapped' => false,
'class' => 'AppBundle:Nome_esame',
'required' => true,
'multiple' => true,
'data' => array($this->em->getReference("AppBundle:Nome_esame", $id_Nome_esame1), $this->em->getReference("AppBundle:Nome_esame", $id_Nome_esame2)),
'choice_label' => 'nome',
// 'disabled' => 'disabled',
'attr' => array(
'placeholder' => 'Esami',
'class' => 'max_width esame_row select_esame',
// 'class'=>'col-md-12 col-md-offset-0 col-xs-9 col-xs-offset-3 ',
)
))
To get the entity manager, if you use the formType as a service, inject doctrine into it, if not, just past it via __construct.
Hope this helps,
Alexandru Cosoi

Magento2.1.5 How can i add multipul custom fields on customer registration form(admin panel)

I have added the single field in the customer registration form in admin end.
But i want to add the one more (multipul fields ).This is my code .
$customerSetup->addAttribute(Customer::ENTITY, 'Company_name', [
'type' => 'varchar',
'label' => 'Company Name tst3',
'input' => 'text',
'required' => true,
'sort_order' => 1000,
'position' => 1000,
'system' => 0,
]);
$attribute = $customerSetup->getEavConfig()->getAttribute(Customer::ENTITY, 'Company_name')
->addData([
'attribute_set_id' => $attributeSetId,
'attribute_group_id' => $attributeGroupId,
'used_in_forms' => ['adminhtml_customer'],
'used_in_forms' => ['customer_account_create'],
]);
This is the code for addded single fields and it is working fine .
Now I am trying the code for add one more field.
$customerSetup->addAttribute(Customer::ENTITY, 'Company_name', [
'type' => 'varchar',
'label' => 'Company Name tst3',
'input' => 'text',
'required' => true,
'sort_order' => 1000,
'position' => 1000,
'system' => 0,
],'Admin_email', [
'type' => 'varchar',
'label' => 'Admin Email',
'input' => 'input',
'required' => true,
'sort_order' => 1000,
'position' => 1000,
]);
$attribute = $customerSetup->getEavConfig()->getAttribute(Customer::ENTITY, 'Company_name','Admin_email')
->addData([
'attribute_set_id' => $attributeSetId,
'attribute_group_id' => $attributeGroupId,
'used_in_forms' => ['adminhtml_customer'],
'used_in_forms' => ['customer_account_create'],
]);
you can go at it by putting the desired attributes in an array like so
$attributesInfo = [
'attribut1' => [
'type' => 'varchar',
'label' => 'Company Name tst3',
'input' => 'text',
'required' => true,
'sort_order' => 1000,
'position' => 1000,
'system' => 0,
],
'attribut2' => [
'type' => 'varchar',
'label' => 'Admin Email',
'input' => 'text',
'required' => true,
'sort_order' => 1000,
'position' => 1000,
'system' => 0,
],
];
foreach ($attributesInfo as $attributeCode => $attributeParams) {
$customerSetup->addAttribute(Customer::ENTITY, $attributeCode, $attributeParams);
}
and then the other part involving eav
$companyAttribute= $customerSetup->getEavConfig()->getAttribute(Customer::ENTITY, 'attribute1');
$companyAttribute->addData([
'attribute_set_id' => $attributeSetId,
'attribute_group_id' => $attributeGroupId,
'used_in_forms' => ['handle1','handle2'],
]);
$adminEmailAttribute= $customerSetup->getEavConfig()->getAttribute(Customer::ENTITY, 'attribute2');
$adminEmailAttribute->addData([
'attribute_set_id' => $attributeSetId,
'attribute_group_id' => $attributeGroupId,
'used_in_forms' => ['handle1','handle2'],
]);
here's a decent tutorial (2.1 or higher)
http://www.extensions.sashas.org/blog/magento-2-1-3-how-to-make-customer-attribute-update.html
should've asked in magento.stackexchange

Contao Wrap Leff and Right Class TL_DCA Fields

I am using TL_DCA Feature in Contao and i want to wrap the fields inside left and right container.
$GLOBALS['TL_DCA']['table_name'] = array
(
// Config
'config' => array
(
'dataContainer' => 'Table',
),
// List
'list' => array
(),
// Fields
'fields' => array
(
'field1' => array
(
'label' => array('Suchname', 'Suchname'),
'exclude' => true,
'inputType' => 'text'
),
'field2' => array
(
'label' => array('Firma', 'Firma'),
'exclude' => true,
'inputType' => 'text'
),
'field3' => array
(
'label' => array('Name', 'Name'),
'exclude' => true,
'inputType' => 'text',
'eval' => array('mandatory' => true)
),
'field4' => array
(
'label' => array('Vorname', 'Vorname'),
'exclude' => true,
'inputType' => 'text'
),
)
)
Wrap Field and Filed 2 inside left class and Field 3 and Field 4 inside right class. So please help here.
Thanks in advance..!!!
It's possible to specific css classes for the fields:
'eval' => array('tl_class'=>'w50'),
w50 stands for width = 50%
for example:
'field1' => array
(
'label' => array('Suchname', 'Suchname'),
'exclude' => true,
'inputType' => 'text',
'eval' => array('tl_class'=>'w50'),
),
'field2' => array
(
'label' => array('Firma', 'Firma'),
'exclude' => true,
'inputType' => 'text'
'eval' => array('tl_class'=>'w50'),
),

Access translated property of collection in form

I have a form with a collection. My form "PageType" with a collection look like this.
$builder->add('sections', 'collection', array(
'type' => new SectionType($this->securityContext, $this->entityManager) ,
'allow_add' => true,
'allow_delete' => true,
'label' => false,
'prototype' => true,
'prototype_name' => '__sectionPrototype__',
'options' => array(
'label' => false,
)
And my second form which represents the collection "SectionType" look like this.
->add('translations', 'a2lix_translations', array(
'fields' => array(
'title' => array(
'field_type' => 'text',
'label' => 'title',
'attr' => array('class' => 'rte sectionTitle')
),
'text' => array(
'field_type' => 'textarea',
'label' => 'hintText',
'attr' => array('class' => 'rte sectionDescription')
)
)
))
How can i access from twig the translations fields?
I think that is not possible. Maybe somebody could correct me if I'm wrong.
fields is an option item for a2lix_translations. If you would have Form object you might be able to do that, but in fact, you have FormView which represents built form.
Alternatively, you could pass that array via standard return from controller and into your twig. Does that sound good?

How to make checkbox checked?

I have this field in form builder
->add('pay_method', 'choice', array(
'choices' => array(
'telnet' => 'Image',
),
'expanded' => true,
'label' => 'Способ оплаты',
))
with ony one option yet, but how can i make this checked?
Add attr index with 'checked' => 'checked':
->add('pay_method', 'choice', array(
'choices' => array(
'telnet' => 'Image',
),
'expanded' => true,
'label' => 'Способ оплаты',
'attr' => array('checked' => 'checked')
))
Set it on the object or array the form is used for.
You can set the default value by either setting it in your domain model:
private $pay_method = 'telnet';
or
$object->pay_method = 'telnet'
or by specifying the "data" option of the field:
$builder->add('pay_method', 'choice', array(
'choices' => array(
'telnet' => 'Image',
...
),
'data' => 'telnet',
'expanded' => true,
'label' => ...,
));
Ok, i did it through JavaScript

Resources