我也没有在文档中找到,所以绕过Ng-admin
- 使用AngularJS
. 这是我的带有RestangularProvider
和 native的版本JS
:
JS
RestangularProvider.setErrorInterceptor(function(response, deferred, responseHandler){
var removeClass = document.querySelectorAll('.has-error'),
removeError = document.querySelectorAll('.field-error');
if(removeClass.length) {
for(var i in removeClass){
if(removeClass[i] && removeClass[i].parentElement) {
removeClass[i].classList.remove('has-error');
}
}
}
if(removeError.length > 0) {
for(var i in removeError){
if(removeError[i] && removeError[i].parentElement) {
removeError[i].parentElement.removeChild(removeError[i]);
}
}
}
if(response.data && response.data.errors) {
for(var i in response.data.errors) {
var element = document.querySelector('#row-' + response.data.errors[i].property_path),
newEl = document.createElement('div');
if(element) {
newEl.className = "field-error col-sm-2 col-md-3";
newEl.innerHTML = '<div class="alert alert-danger"><strong>' + response.data.errors[i].message + '</strong></div>';
element.classList.add('has-error');
element.classList.remove('has-success');
element.appendChild(newEl);
}
}
response.data = "Ошибка формы";
}
return true;
});
CSS
.has-success .alert {
display: none;
}
.has-success .checkbox, .has-success .checkbox-inline, .has-success .control-label, .has-success .form-control-feedback, .has-success .help-block, .has-success .radio, .has-success .radio-inline, .has-success.checkbox label, .has-success.checkbox-inline label, .has-success.radio label, .has-success.radio-inline label {
color: #3c763d !important;
}
.has-success .form-control,
.has-success .form-control:focus {
border-color: #3c763d;
-webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075) !important;
box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075) !important;
}
.has-success .ta-editor {
border-color: #3c763d !important;
}
.has-error .ta-editor {
border-color: #a94442;
}
response.data.errors
还给我 Symfony2。