Forms Symfony5.2更改选择类型的表单操作
如何在Symfony表单中更改choiceType 大概是这样的:Forms Symfony5.2更改选择类型的表单操作,forms,symfony,action,choice,Forms,Symfony,Action,Choice,如何在Symfony表单中更改choiceType 大概是这样的: if ($form->onChange()) { //action { Symfony作为后端仅在提交表单时注意到更改。提交前对表单的任何更改都必须通过Javascript进行检测。如果表单映射实体,则可以添加事件订阅服务器以检查某些属性是否已更改 namespace App\EventSubscriber\Doctrine use Doctrine\Common\EventSubscriber; use Do
if ($form->onChange()) {
//action
{
Symfony作为后端仅在提交表单时注意到更改。提交前对表单的任何更改都必须通过Javascript进行检测。如果表单映射实体,则可以添加事件订阅服务器以检查某些属性是否已更改
namespace App\EventSubscriber\Doctrine
use Doctrine\Common\EventSubscriber;
use Doctrine\ORM\Event\PreUpdateEventArgs;
use Doctrine\ORM\Events;
class DoctrinePreUpdateSubscriber implements EventSubscriber
{
/**
* @return array<string, string>
*/
public function getSubscribedEvents(): array
{
return [
Events::preUpdate => 'preUpdate',
];
}
private function preUpdate(PreUpdateEventArgs $args): void
{
if ($args->getObject() instanceof SomeEntity && $args->hasChangedField('someProperty')) {
}
}
}
namespace-App\EventSubscriber\doctor
使用条令\公共\事件订阅者;
使用条令\ORM\Event\PreUpdateEventArgs;
使用条令\ORM\Events;
类DoctrinePreUpdateSubscriber实现EventSubscriber
{
/**
*@return数组
*/
公共函数getSubscribedEvents():数组
{
返回[
事件::preUpdate=>“preUpdate”,
];
}
私有函数预更新(PreUpdateEventArgs$args):无效
{
如果($args->getObject()instanceof SomeEntity&&$args->hasChangedField('someProperty')){
}
}
}