File tree Expand file tree Collapse file tree 4 files changed +29
-39
lines changed
Customer/Controller/Adminhtml/Index Expand file tree Collapse file tree 4 files changed +29
-39
lines changed Original file line number Diff line number Diff line change @@ -57,9 +57,11 @@ protected function _validateCustomer($response)
57
57
}
58
58
59
59
if (!$ errors ->isValid ()) {
60
+ $ messages = [];
60
61
foreach ($ errors ->getMessages () as $ error ) {
61
- $ this -> messageManager -> addError ( $ error) ;
62
+ $ messages [] = $ error ;
62
63
}
64
+ $ response ->setMessages ($ messages );
63
65
$ response ->setError (1 );
64
66
}
65
67
@@ -90,9 +92,11 @@ protected function _validateCustomerAddress($response)
90
92
91
93
$ errors = $ addressForm ->validateData ($ formData );
92
94
if ($ errors !== true ) {
95
+ $ messages = [];
93
96
foreach ($ errors as $ error ) {
94
- $ this -> messageManager -> addError ( $ error) ;
97
+ $ messages [] = $ error ;
95
98
}
99
+ $ response ->setMessages ($ messages );
96
100
$ response ->setError (1 );
97
101
}
98
102
}
@@ -114,9 +118,8 @@ public function execute()
114
118
}
115
119
$ resultJson = $ this ->resultJsonFactory ->create ();
116
120
if ($ response ->getError ()) {
117
- $ layout = $ this ->layoutFactory ->create ();
118
- $ layout ->initMessages ();
119
- $ response ->setHtmlMessage ($ layout ->getMessagesBlock ()->getGroupedHtml ());
121
+ $ response ->setError (true );
122
+ $ response ->setMessages ($ response ->getMessages ());
120
123
}
121
124
122
125
$ resultJson ->setData ($ response );
Original file line number Diff line number Diff line change @@ -29,6 +29,15 @@ define([
29
29
success : function ( resp ) {
30
30
if ( ! resp . error ) {
31
31
save . resolve ( ) ;
32
+ } else {
33
+ $ ( 'body' ) . notification ( 'clear' ) ;
34
+ $ . each ( resp . messages , function ( key , message ) {
35
+ $ ( 'body' ) . notification ( 'add' , {
36
+ error : resp . error ,
37
+ message : message ,
38
+ messageSelector : '#anchor-content'
39
+ } ) ;
40
+ } ) ;
32
41
}
33
42
} ,
34
43
complete : function ( ) {
Original file line number Diff line number Diff line change @@ -13,7 +13,8 @@ define([
13
13
$ . widget ( 'mage.notification' , {
14
14
options : {
15
15
templates : {
16
- global : '<div class="messages"><div class="message <% if (data.error) { %>error<% } %>"><div><%- data.message %></div></div></div>'
16
+ global : '<div class="messages"><div class="message <% if (data.error) { %>error<% } %>"><div><%- data.message %></div></div></div>' ,
17
+ error : '<div class="messages"><div class="message message-error error"><div data-ui-id="messages-message-error" ><%- data.message %></div></div></div>'
17
18
}
18
19
} ,
19
20
@@ -47,20 +48,20 @@ define([
47
48
* @param {Object } data - Data with a message to be displayed.
48
49
*/
49
50
add : function ( data ) {
50
- var message = mageTemplate ( this . options . templates . global , {
51
+ var template = data . error ? this . options . templates . error : this . options . templates . global ;
52
+ var message = mageTemplate ( template , {
51
53
data : data
52
54
} ) ;
53
-
54
- $ ( '#messages' ) . append ( message ) ;
55
-
55
+ var messageSelector = data . messageSelector || '.messages' ;
56
+ $ ( messageSelector ) . prepend ( message ) ;
56
57
return this ;
57
58
} ,
58
59
59
60
/**
60
61
* Removes error messages.
61
62
*/
62
63
clear : function ( ) {
63
- $ ( '# messages' ) . html ( '' ) ;
64
+ $ ( '. messages' ) . html ( '' ) ;
64
65
}
65
66
} ) ;
66
67
Original file line number Diff line number Diff line change 145
145
* @param {Object } data - Data that came from backend.
146
146
*/
147
147
_showErrors : function ( data ) {
148
- var attributes = data . attributes || { } ,
149
- element ;
150
-
151
- if ( data . attribute ) {
152
- attributes [ data . attribute ] = data . message ;
153
- }
154
-
155
- $ ( 'body' ) . notification ( 'clear' ) ;
156
-
157
- _ . each ( attributes , function ( message , code ) {
158
- element = this . _getByCode ( code ) ;
159
-
160
- if ( ! element . length ) {
161
- $ ( 'body' ) . notification ( 'add' , {
162
- error : true ,
163
- message : message
164
- } ) ;
165
-
166
- return ;
167
- }
168
-
169
- element
170
- . addClass ( 'validate-ajax-error' )
171
- . data ( 'msg-validate-ajax-error' , message ) ;
172
-
173
- this . validate . element ( element ) ;
174
-
175
- } , this ) ;
148
+ $ ( 'body' ) . notification ( 'clear' )
149
+ . notification ( 'add' , {
150
+ error : data . error ,
151
+ message : data . message
152
+ } ) ;
176
153
} ,
177
154
178
155
/**
You can’t perform that action at this time.
0 commit comments