Symfony: How to customize the "none" label appearing on radio field choices? - forms

I'm using radio buttons with "required" => false. This makes a "none" option appear along with my other choices.
How can I customize this label (let's say I would want to display "null" instead of "none") ?

If you want to remove it set placeholder to false
->add('color', ChoiceType::class, array(
'choices' => array('Red' => 1, 'Blue' => 2, 'Green' => 3),
'expanded' => true,
'required' => false,
'placeholder' => false
));

Use placeholder option to change the label for "None" radio input:
->add('color', ChoiceType::class, array(
'choices' => array('Red' => 1, 'Blue' => 2, 'Green' => 3),
'expanded' => true,
'required' => false,
'placeholder' => 'Null', // <---- \o/
));
Preview:
The placeholder option was introduced in Symfony 2.6 (doc)

Related

How to Hide or Show Custom attribute based on other custom attribute in Product detail/edit page from Adminpanel Magento 2.4?

I have created the Product's custom attributes programmatically(Setup->Installdata.php).
$eavSetup->addAttribute(
\Magento\Catalog\Model\Product::ENTITY,
'serial_code_use_customer',
[
'type' => 'int',
'backend' => '',
'frontend' => '',
'label' => 'Issue By Customer Group',
'input' => 'boolean',
'class' => '',
'source' => \Magento\Eav\Model\Entity\Attribute\Source\Boolean::class,
'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
'visible' => true,
'required' => false,
'user_defined' => true,
'default' => '0',
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => false,
'used_in_product_listing' => false,
'unique' => false,
'apply_to' => 'simple,configurable,virtual,bundle,downloadable',
'group' => self::GROUP_LABEL,
'sort_order' => 3,
'note' => 'Enable automatic issuing of codes based on customer group.'
]
);
$eavSetup->addAttribute(
\Magento\Catalog\Model\Product::ENTITY,
'serial_code_customer_groups',
[
'type' => 'varchar',
'backend' => '',
'frontend' => '',
'label' => 'Select Customer Groups',
'input' => 'multiselect',
'class' => '',
'source' => \Magento\Customer\Model\Customer\Attribute\Source\Group::class,
'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
'visible' => true,
'required' => false,
'user_defined' => true,
'default' => '0',
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => false,
'used_in_product_listing' => false,
'unique' => false,
'apply_to' => 'simple,configurable,virtual,bundle,downloadable',
'group' => self::GROUP_LABEL,
'sort_order' => 4,
'note' => 'Customers in selected groups will be issued codes automatically when product is ordered.'
]
);
I want to Hide or Show a Custom attribute based on other custom attributes in the Product detail/edit page from Adminpanel Magento 2.4.x?
For example, there is a toggle on click (yes/no) the Customer Groups will be Hide / Show.
To hide custom product attributes from the admin product detail page you need to create UpgradeData.php in the My/Catalog/Setup directory.
Code:
$eavSetup->updateAttribute(Product::ENTITY, $attrCode, 'is_visible',
'0');

Hide a label from an Embedded Form Type in a Collection type

I have a form collection type called ContactType which has a CollectionType field called contact2Companies with entry_type AddCompanyFromContactType. AddCompanyFromContactType has a field company which uses another form type CompanyNameType.
In the frontend, we see the label Unternehmen from ContactType. In the grey box, first line, is the label Name des Unternehmens which comes from AddCompanyFromContactType and under this the label Name which comes from CompanyNameType.
How can I hide/remove the label Name?
Code Excerpts
ContactType
$builder
->add('contact2Companies', CollectionType::class, [
'required' => false,
'label' => 'contact.companies',
'entry_type' => AddCompanyFromContactType::class,
'allow_add' => true,
'allow_delete' => true,
])
AddCompanyFromContactType
$builder
->add('company', CompanyNameType::class, [
'required' => true,
'label' => 'company.name',
'attr' => [
'autofocus' => true,
],
])
CompanyNameType
$builder
->add('name', TextType::class)
Simply add this to the field name of CompanyNameType:
$builder
->add('name', TextType::class, [
'label' => false,
])
CollectionType has 2 levels of labels. One for all inputs, and the other for each input in Collection.
$builder->add('name', CollectionType::class, [
'entry_type' => MoneyType::class,
'label' => 'Top Name Label',
'entry_options' => [
'label' => 'Name Label',
],
])
label on the first level is rendered in <legend> tag and it is one for all inputs.
label under entry_options is for each row.
According to your needs, you can set them false.

Symfony Forms add placeholder to the prototype of collection field

I'm looking for a way to add placeholders to the collection field prototype. Adding the attribute 'placeholder' does not make any effect.
I tried using prototype_data and replacing the value-attribute with placeholder in twig, but it throws an error if field type is a number, and passed text value can't be converter to a number.
$builder->add('fees', CollectionType::class, [
'allow_add' => true,
'allow_delete' => true,
'delete_empty' => true,
'entry_type' => TextType::class,
'prototype' => true,
'attr' => [
'placeholder' => 'Fee Type',
],
])
Generally you can embed any available option for the Form Type specified in entry_type option (in your case TextType) to all the entries of your CollectionType through the entry_options.
Specifically for your problem you should use this:
$builder->add('fees', CollectionType::class, [
'allow_add' => true,
'allow_delete' => true,
'delete_empty' => true,
'entry_type' => TextType::class,
'prototype' => true,
'entry_options' => [
'attr' => [
'placeholder' => 'Fee Type',
]
]
])
Documentation here

How to hide delete icon in kartik Detail view yii2?

I am using Kartik/Detail View. I only want to show the edit button in the panel and hide delete icon in the panel.My code is :
<?= DetailView::widget([
'model' => $model,
'mode' => 'view',
'bordered' => true,
'striped' => true,
'panel' => [
'heading' => $this->title,
'type' => DetailView::TYPE_INFO,
],
'container' => ['id'=>'kv-demo'],
'responsive' => true,
'hover' => true,
'hAlign'=>true,
'vAlign'=>true,
'fadeDelay'=>true,
'attributes' => [
'business_name',
'address2',
'city',
'state',
'zip',
'telephone',
'fax',
'email:email',
],
]) ?>
How can I hide delete icon ?
http://demos.krajee.com/detail-view#option-buttons1
Use 'buttons1' => '{update}', to hide delete.
<?= DetailView::widget([
'model' => $model,
'mode' => 'view',
'bordered' => true,
'striped' => true,
'panel' => [
'heading' => $this->title,
'type' => DetailView::TYPE_INFO,
],
'buttons1' => '{update}',
You can do this from _columns.php file of view folder with following option
Here you can add template with action that you need to show in the detail view (in this example view action is used and Assign with fa-gear icon is displayed in view)
[
'class' => 'kartik\grid\ActionColumn',
'dropdown' => false,
'vAlign'=>'middle',
'template' => '{view}',
'urlCreator' => function($action, $model, $key, $index) {
return Url::to([$action,'id'=>$key]);
},
'buttons'=>[
'view' => function ($url, $model, $key) {
return Html::a('<span class="fa fa-gears"> Asign</span>', ['view', 'id'=>$model->id],['title'=>'Asign','role'=>'modal-remote','data-toggle'=>'tooltip']);
},
]
],

zf2 form collection don't show element description

When the collection element is rendered , description element does not appear.
ZF2 seems to ignore the description option in the form collection.
Form
$this->add(array(
'type' => 'Zend\Form\Element\Collection',
'name' => 'value',
'options' => array(
'label' => 'Please choose value',
'count' => 1,
'should_create_template' => true,
'target_element' => new ValueFieldset($objectManager)
)
));
Form Fieldset: ValueFieldset
$this->add(array(
'name' => 'name',
'type' => 'Zend\Form\Element\Text',
'options' => array(
'label' => 'Values',
'label_attributes' => array(
'class' => 'form-label'
),
'description' => 'X',
'multiple' => true,
),
)
);
View
echo $this->formCollection($values);