У меня есть форма, которая встраивает collectionType. Тип Collection использует две подчиненные формы.
Когда я устанавливаю обязательную опцию для полей, принадлежащих форме CollectionType или Subforms, она не работает: ни красный *, ни ошибки проверки формы ...
У меня есть форма, которая встраивает collectionType. Тип Collection использует две подчиненные формы.
Когда я устанавливаю обязательную опцию для полей, принадлежащих форме CollectionType или Subforms, она не работает: ни красный *, ни ошибки проверки формы ...
Что я пропустил?
Classe:
class: App\Entity\Classe
label: 'Classes'
form:
fields:
- { property: 'classe', label: 'Classe Name'}
- { property: 'maxextcuth', label: 'Max ext. Cu', type: 'entity'}
- { property: 'maxintcuth', label: 'Max int. Cu', type: 'entity'}
- { property: 'enabled', label: 'Enabled'}
- { type: 'section', label: 'Price rules', icon: 'euro' }
- property: 'classePrices'
label: false
type: 'collection'
type_options:
entry_type: App\Form\Type\ClassePriceType
allow_delete: true
allow_add: true
by_reference: false
prototype: true
block_prefix: 'price_collection'
class ClassePriceType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('priceform', PriceformType::class, [
'data_class' => ClassePrice::class,
'block_prefix' => 'mainprice_block'
]);
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => ClassePrice::class,
'attr' => array(
'class' => 'fullwidth'
)
]);
}
}
class PriceformType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('pricecover', ChoiceType::class, [
'label' => 'Price type',
'placeholder' => 'Select a price option',
'choices' => [ 'Global' => '1' ,'Step' => '2'],
'required' => true
])
->add('rangesubform', RangesubformType::class, [
'data_class' => ClassePrice::class,
'block_prefix' => 'range_block'
])
->add('pricesubform', PricesubformType::class, [
'data_class' => ClassePrice::class,
'block_prefix' => 'price_block'
]);
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'inherit_data' => true
]);
}
}
class RangesubformType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('rangetype', EntityType::class, [
'class' => Ptur::class,
'label' => 'Step type',
'choice_translation_domain'=> true,
'required' => true
])
->add('rangeformat', EntityType::class, [
'class' => Format::class,
'label' => 'Format',
'required' => true
])
->add('rangemin', IntegerType::class, [
'label' => 'Range min',
'required' => true
]);
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'inherit_data' => true,
'attr' => array(
'class' => 'form-horizontal'
)
]);
}
}