Hel*_*esh 1 ckeditor symfony symfony4 easyadmin
在使用EasyAdminBundle创建的管理控制台中,我的表单验证仅适用于没有的字段CKEditorType
。一些字段需要编辑,因此我使用FOSCKEditorBundle实现了所见即所得。
有关领域的摘录:
- { property: 'content', type: 'FOS\CKEditorBundle\Form\Type\CKEditorType'}
Run Code Online (Sandbox Code Playgroud)
当我提交带有空白“内容”字段的表单时,InvalidArgumentException
出现错误消息:Expected argument of type "string", "NULL" given.
而不是诸如“ 请填写此字段”之类的验证错误。
没有CKEditor的相关领域的代码片段:
- { property: 'content' }
Run Code Online (Sandbox Code Playgroud)
=>验证非常有效。
我的实体字段:
/**
* @ORM\Column(type="text")
* @Assert\NotBlank
* @Assert\NotNull
*/
private $content;
Run Code Online (Sandbox Code Playgroud)
Symfony探查器显示此字段确实具有required
属性。
如何使用CKEditor
字段类型启用验证?
这与ckeditor无关。您所需要做的就是修复您的内容设置程序,以通过参数接受NULL。然后,验证过程应正确触发:
public function setContent(?string $content) {
$this->content = $content;
retrun $this;
}
Run Code Online (Sandbox Code Playgroud)
在将请求值设置为表单数据(在您的情况下为实体)字段后,将执行验证。您可以在此处找到表单提交流程:https : //symfony.com/doc/current/form/events.html#submitting-a-form-formevents-pre-submit-formevents-submit-and-formevents-post-submit
归档时间: |
|
查看次数: |
208 次 |
最近记录: |