I have a front end reg form saving profiles via ajax. All user and profile data is getting stored ok. The problem comes with validation.
It seems Craft likes to load the errors for certain fields first:
{% macro errorList(errors) %}
So the above fills the error array with username, title and email before processing the others. In ajax am getting the errors like:
function appendErrors(errors) {
$.each(errors, function(field, errors) {
appendError(field, errors);
});
}
function appendError(field, errors) {
var $errorList = $( '<ul class="errors" />' );
$.each(errors, function(index, error) {
$errorList.append($('<li>').html(error));
console.log(error);
});
$("input[name=" + field + "]").after($errorList);
}
I'd like to show all the errors to the user at once on page for sensible UX reasons. So quick brain check - is Craft really doing this? If so, then I see my options like:
- Could switch to a pure jQuery/js validation
- Could try and manipulate the error array and reindex based on tabindex?
- Could try overriding Craft's validation thru plugin
Has anyone else come at this in earnest?
UsersController->actionSaveUser()
? Are you running Craft Pro and the latest version of Craft?UsersService->saveUser()
validates the UserRecord first, then any custom fields/content and only then will return false with all errors attached to theUserModel
. github.com/pixelandtonic/Craft-Release/blob/master/app/services/… – Brad Bell Apr 12 '17 at 18:13