x-editable render html error response - x-editable

We have a system where customer information is editable in-line.
When someone puts in an email that already exists, I want to return the error message:
Email already exists. <a href='/find-duplicates/id'>Click here to find possible duplicates of this customer</a>
I would like the user to be able to click on the link when s/he sees the error message. The error message is very easy to send; it's rendering the html that's the problem.

Trying to display same kind of link in x-editable field error as #iateadonut.
For anyone wanting to display html in x-editable errors, assuming you have the error with html sent back from server with response status code different from 500 (400 maybe) try :
$(function() {
$('#your_field_id').editable({
error: function(response, newValue) {
if(response.status === 500) {
return 'Service unavailable. Please try later.';
} else {
var error = $.parseHTML( response.responseText )
$(".editable-error-block").html(error)
}
},
});
})
Mostly html parsing response error and injecting it inside x-editable error block.
Found in x-editable doc, options.

Related

How to show custom notifications or error message at admin panel for prestashop 1.7.7.7?

​
Hi, 
I've been trying a lot of options to manage an exception and show an error at admin panel but nothing seems to work.
I'm at the postProcess method of a custom module. After the user sends a csv file through a form and the data is checked (everything works fine here), if an exception occurs I need to show a message, stop and redirect to the same page. 
I've tried this: 
this->get('session')->getFlashBag()->add('error',$msg);
Tools::redirectAdmin('index.php?controller='.$controller.'&token='.$token);
this: 
header("HTTP/1.0 400 Bad Request");
die(json_encode(array( 'error' => array($this->l(' Error') ))));
(that one works but shows a blank page with the message, not the message inside the admin panel) 
also this: 
$this->context->smarty->assign(array(
'token' => Tools::getAdminTokenLite('AdminModules'),
'errors' => $this->errors
));
$this->setTemplate('ExcelProcess.tpl');
and {$errors|var_dump} at the tpl displays null...
... and many other options. 
I can't find anything either about backoffice custom notifications at the PS docs, only about front custom notifications.
Any clue? 
 
Thanks a lot! 
Miguel
PostProces code: https://drive.google.com/file/d/175nhUPDlzi6T8rZjjE8Desnzq-mtYzNQ/view?usp=sharing
​Tpl code: https://drive.google.com/file/d/17EONOCJ60L4Gp_GidzvwCQwMyTrRXapF/view?usp=sharing
Adding an error in postProcess() can be achieved by setting
$this->errors[] = $this->l('My error');
or
$this->context->controller->errors[] = $this->l('My error');
during your form submission checks.
Form will be rendered with your error messages into a red box.
If you want to show an alert without reloading the page instead, you'll have to perform an AJAX call to your AdminController, get back a JSON response and render your error message as a result of the execution of the call.
See offical docs

Uploading image [Cypress]

I'm trying to upload a jpeg image from local files to a webpage developed here in my job. The thing is, we need to click on the page to open the file explorer and then select the image (or drag and drop into the same spot that may be clicked).
Here is a picture from the web page
I don't know how could i do that, i was trying some code that i've seen in "https://medium.com/#chrisbautistaaa/adding-image-fixtures-in-cypress-a88787daac9c". But don't worked. I actually don't know how it works exactly, could anyone help me?
Here is my code
After #brendan's help, I was able to solve the problem by finding an input that was "hidden" under an element. However, before that I tried drag-n-drop, and cypress returned me an error (despite the successful upload). The context was, immediately after the upload, the element re-renders and cypress told me that:
.
Beside the success with input element, i was wondering how it would be possible to resolve this error, is it possible to do something internally to cypress to ignore or wait until the element re-renders back to normal?
Solutions suggested by cypress:
We're doing this using cypress-file-upload
Here's an example from our code:
cy.fixture(fileName).then(fileContent => {
cy.get(selectors.dropZoneInput).upload(
{ fileContent, fileName, mimeType: "application/pdf" },
{ subjectType: "drag-n-drop" }
);
});
For your purpose, I think this will work:
cy.fixture(imagePath).then(fileContent => {
cy.get(".upload-box").first().upload(
{ fileContent, fileName, mimeType: "image/jpeg" },
{ subjectType: "drag-n-drop" }
);
});

How to change required field error message?

I have two required columns in a custom list. When adding an item using OOTB new form, the required field validator shows same error message "You can't leave this blank." for both required columns. Does anybody know what is the best way to show different messages for each of them?
You can use Strings.STS to override message. Just add this code to your page or master page if you want to apply all your site.
<script type="text/javascript">
$(document).ready(function () {
try {
if (Strings.STS.L_SPClientRequiredValidatorError != null) {
Strings.STS.L_SPClientRequiredValidatorError = "What ever you want!";
}
}
catch (exception) { }
});
</script>
For more information: SharePoint 2010 use message: "You must specify a value for this required field." It showed after validating from the server. SharePoint 2013 shows a message "You can't leave this blank." after validating from the client.
But, if you use Sharepoint webpart and Sharepoint control, it still shows a message same as Sharepoint 2010. It makes inconsistent from your site.

Meteor IronRouter onBeforeAction causes exception in defer callback

I'm trying to secure my meteor app with iron-router, here's my onBeforeAction function:
this.route('manageUsers', {
path: '/panel/user_management',
layoutTemplate: 'panel',
onBeforeAction: function(){
if((Meteor.user() === null)||(Meteor.user().role !== 'superAdmin')){
Router.go('signIn');
throwAlert('You dont have access to see this page', 'notification');
}
}
});
When I'm trying to go to /panel/user_management subpage by pressing a link button everything goes fine (user is redirected etc.), but when I type the path directly in my browser (localhost:3000/panel/user_management) and hit enter user is not getting redirected and I receive in console Exception in defer callback error. Anyone know what I'm doing wrong?
For additional information, this view lists me all users registered. When I go to this path normally (without error) I see complete user list. When I receive error template doesn't appear in > yield.
Finally, I've solved this - the problem was wrong if statement, here's the correct one:
if((!Meteor.user())||(Meteor.user().role !== 'superAdmin')){}

Yii: Same route but only GET works after confirming there's no controller filter

My urlManager rules: (basically the one comes default)
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',`
My controller:
class SiteController extends Controller {
public function actionSubscribe() {
echo 'gdg';
die();
}
}
My view:
<form method="POST" action="<?php echo $this->createUrl('site/subscribe'); ?>" style="display: inline;">
<input style="margin: 0 18px 0 6px;" type="text" value="e-mail"/>
</form>
When I access it using the url http://localhost/site/subscribe directly it works, but when I type something in the text field and push my enter button to post the form it says The system is unable to find the requested action "error".
I'm very certain that it has something to do with my form. I have so far no problem using active form but for this form I don't have a model and I don't want to use form builder. Any help?
"When I access it using the url http://*/site/subscribe directly it works"
=> You execute subscribe action with GET method.
"but when I type something in the text field and push my enter button to post the form it says The system is unable to find the requested action "error"."
=> You execute subscribe action with POST method.
=> There are some errors and I think Yii try to handle error with your default configure:
return array(
......
'components'=>array(
'errorHandler'=>array(
'errorAction'=>'site/error',
),
),
);
However, Yii can't find error action with your SiteController so it throws The system is unable to find the requested action "error". You can add error action to see information about errors like:
public function actionError()
{
if($error=Yii::app()->errorHandler->error){
$this->render('error', $error);
}
}
More info: The above error variable is an array with the following fields:
code: the HTTP status code (e.g. 403, 500);
type: the error type (e.g. CHttpException, PHP Error);
message: the error message;
file: the name of the PHP script file where the error occurs;
line: the line number of the code where the error occurs;
trace: the call stack of the error;
source: the context source code where the error occurs.