I'm having a Symfony Type ItemType
which is based on an Entity.
class IpQuoteItemsType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('itemName', TextType::class, [
'label' => 'Produktname'
])
...
->add('specialDiscount', PercentType::class, [
'required' => false,
'label' => 'Sonderrabatt',
'mapped' => false,
'attr' => [
'placeholder' => 'Sonderrabatt 0,00 %'
]
])
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => IpQuoteItems::class
));
}
}
Which is used as a CollectionType in the final form:
class IpQuotesType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
...
$builder->add('products', CollectionType::class, [
'entry_type' => IpQuoteItemsType::class,
'data' => $items
]);
}
}
Under no circumstances I receive the unmapped field specialDiscount
. It is still available in the PRE_SUBMIT event of the ItemsType
but can't be found anywhere in the final form QuotesType
.
Is it possible to sumit unmapped data in nested forms?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…