Entity order exists with the Product property.
An OrderType form has been created that allows you to add a Product to an order.
It works, however it is not very interesting.
Instead of showing a simple product, it should be autocomplete.
However, when you select an autocomplete value, some additional fields must be populated with product information.
Choosing a product from autocomplete should fill in two additional fields with a price and a code.
A controller method for returning data has been created, and jquery has some convenient autocomplete functions available.
I know how to hack a solution directly into a form template, but I would like to make a reusable component.
The question is how to create a custom form or extension with this behavior?
class Order {
protected $id;
protected $product;
protected $quantity;
}
class Product {
protected $id;
protected $orders;
protected $name;
protected $price;
protected $code;
}
class OrderType extends AbstractType {
public function buildForm(FormBuilderInterface $builder, array $options) {
$builder
->add('quantity')
->add('product');
}
}
OrderType :
$builder
->add('ppprice', 'text', array('mapped' => false, 'data' => 2));
$builder->addEventListener(
FormEvents::PRE_SET_DATA, function (FormEvent $event) use($builder) {
$form = $event->getForm();
$order = $event->getData();
$builder
->add('ppprice', 'text', array('mapped' => false, 'data' => 21));
$builder
->add('test', 'text', array('mapped' => false, 'data' => 21));
}
);
PRE_SET_DATA, , ppprice .
PRE_SET_DATA ?