pawsitiwe/sulu-forms-ajax-validation-bundle
最新稳定版本:0.2.1
Composer 安装命令:
composer require pawsitiwe/sulu-forms-ajax-validation-bundle
包简介
A bundle for Sulu form ajax validation
关键字:
README 文档
README
Installation
composer require pawsitiwe/sulu-forms-ajax-validation-bundle
Setup
Service Registration
The extension needs to be registered as symfony service.
services: Pawsitiwe\Controller\ValidationController: arguments: $formBuilder: '@sulu_form.builder' tags: ['controller.service_arguments']
Bundle Registration
return [ Pawsitiwe\SuluFormsAjaxValidationBundle::class => ['all' => true], ]
Route Registration
sulu_frontend_validation: resource: '@SuluFormsAjaxValidationBundle/Resources/config/routes.yaml' prefix: /
Usage
The route /ajax/form/validate returns the form validation as JSON
Twig Integration
Include the AJAX-enabled form in your templates using the provided partial:
{% include '@SuluFormsAjaxValidation/forms/partials/ajax_form.html.twig' with {
form: content.form,
successText: view.form.entity.successText,
errorText: 'Custom error message' # optional
} %}
This partial automatically:
- Uses the custom form theme ajax_form.html.twig
- Displays error and success messages
- Adds type-specific and additional CSS classes for styling
Example Response
{
"message": "",
"valid": false,
"fields": [
{
"id": "dynamic_form1_email",
"valid": false,
"modified": true,
"violation": {
"message": "This value should not be blank."
}
},
{
"id": "dynamic_form1_lastName",
"valid": true,
"modified": false
}
]
}
Notes
- The
formparameter must be a Sulu Form object. successTextis optional; if empty, the default translationajax_form.successwill be used.errorTextis optional; if empty, the default translationajax_form.errorwill be used.
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-09-18