cakephp-3.7 - CakePHP 3 自定义表单
问题描述
我正在使用 CakePHP3 和 Angular 为表单输入提供一些前端验证。这工作得很好,但我希望尽量减少我的前端标记 - 如下:
$this->Form->control('Name', [
'placeholder' => 'Test',
'ng-model' => 'listing.test',
'templateVars' => [
'has_errors' => 'ng-class="{\'has-error\': addListing.$submitted && addListing.name.$invalid}"',
'error' => '<div class="error-message" ng-show="addListing.$submitted && addListing.name.$invalid">Please specify your name</div>',
]
]);
在我的 app_form.php 我有以下内容:
'input' => '<input class="form-control mb15" type="{{type}}" name="{{name}}"{{attrs}} />{{error}}',
我不想为每个输入重复'<div class="error-message"...',最好只传递'ng-show'。
我的想法是做类似的事情:
'templateVars' => [
'has_errors' => 'ng-class="{\'has-error\': addListing.$submitted && addListing.name.$invalid}"',
'show' => 'addListing.$submitted && addListing.name.$invalid',
'message' => 'Please input your name'
]
'customError' => '<div class="error-message" ng-show"{{show}}>{{error-message}}</div>',
'input' => '<input class="form-control mb15" type="{{type}}" name="{{name}}"{{attrs}} />{{customError}}',
但是,我认为这种自定义超出了可能,因为我将创建自己的模板密钥。这可能吗?
解决方案
推荐阅读
- python - 如何使用 python 成功接收 Google Drive v3 推送通知?
- html - Flexbox 没有响应
- ssl - java 在集成测试中以单元测试方式测试 webhook
- javascript - 子组件中的函数不能在父组件中设置状态
- php - Symfony 4 投票者注释(@IsGranted)
- python - Python:满足大于或等于语句时的问题也会打印出更多
- python - 使用 GeoPy Nominatim 的正确方法
- python - Wagtail 在索引页面中呈现任何路径
- angular - Ngx-editor 未在任何浏览器中显示
- jenkins - 访问 Jenkins 中的端口