-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement nice validation error display #191
Conversation
@@ -53,44 +53,60 @@ public function set($callback, $args = []) | |||
} | |||
|
|||
return parent::set(function () use ($callback) { | |||
$chain = new jQuery(new jsExpression('this')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there are no changes here - only alignment.
}, $actions)); | ||
|
||
$this->app->terminate(json_encode(['success'=>true, 'message'=>'Success', 'eval'=>$ajaxec])); | ||
} catch (\atk4\data\ValidationException $e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is new code added. Everything above is just re-aligned.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
As Alain said in his comment - not sure why we need message and eval=alert both at the same time.
-
I still don't know how to run UI JS on my local repo. JS methods simply return json and nothing catches it.
See video: https://www.useloom.com/share/c81f35682c5648ea8f1885fd5736c4dc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought - for compatibility, but didn't seem to work :) I'll drop the eval.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can remove more code above which fills now unused $ajaxec variable etc.
]); | ||
$app = new \atk4\ui\App(); | ||
|
||
$app->title = 'Agile UI - Demo Suite'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The version is now displayed in the footer, why duplicate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can probably just do;
catch (\atk4\data\ValidationException $e) {
// Validation exceptions will be presented to user in a friendly way
$this->app->terminate(json_encode(['success'=>false, 'message'=>$e->getHTML()]));
}
I do not think you need to render the $action. Plus sending the exception directly will have the full stack as well display to user.
Imants;
Have you compile the js code using webpack ( npm run build) on your local
repo. Does not look like atk4JS,js is update.
The json output is now catch within the atk4JS file i.e.
$.fn.api.onSuccessTest has been move within atk4JS.
…On Tue, Jul 4, 2017 at 6:35 PM, Imants Horsts ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In src/jsCallback.php
<#191 (comment)>:
>
- $ajaxec = implode(";\n", array_map(function (jsExpressionable $r) {
- return $r->jsRender();
- }, $actions));
+ $ajaxec = implode(";\n", array_map(function (jsExpressionable $r) {
+ return $r->jsRender();
+ }, $actions));
+
+ $this->app->terminate(json_encode(['success'=>true, 'message'=>'Success', 'eval'=>$ajaxec]));
+ } catch (\atk4\data\ValidationException $e) {
1.
As Alain said in his comment - not sure why we need message and
eval=alert both at the same time.
2.
I still don't know how to run UI JS on my local repo. JS methods
simply return json and nothing catches it.
See video: https://www.useloom.com/share/c81f35682c5648ea8f1885fd5736c4
dc
—
You are receiving this because your review was requested.
Reply to this email directly, view it on GitHub
<#191 (comment)>, or mute the
thread
<https://github.com/notifications/unsubscribe-auth/ACGjPpePwUMMtstZsiru5uzjkcyvXgFfks5sKr4ogaJpZM4ONPFo>
.
--
Alain Belair
|
Models now throw "ValidationError" when something is wrong with the data. That's not an applicaiton error, if it's left un-cached then the error should be properly presented to the user.
The form already does that by highlighting appropriate field with the error message, but the standard callback handlers based around jsCallback would show an ugly message.
This PR will display validation errors nicely, if developer didn't bother to take care of them.
Demo now have a [failure] button:
Click it to get this prompt:
The responsible code is: