-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Show values that are duplicate in attribute error msg #10213
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
Show values that are duplicate in attribute error msg #10213
Conversation
return isValid; | ||
}, | ||
|
||
_config.message | ||
messager |
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.
@PieterCappelle Why you can't use msg
variable? Why you declare messager
function?
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 can't use the msg variable because its not in the scope of the function inside the jQuery.validator.addMethod
.
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.
@PieterCappelle msg
variable declared in the scope of main function at the same scope declared messager
function. You can use it.
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.
@omiroshnichenko No, you will be in a javascript closure - don't know the exact javascript scope name but I think it's a closure - . You have to use custom function to display the msg variable. I tried multiple times like code below and it's not working.
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
define([
'jquery',
'mage/backend/validation'
], function (jQuery) {
'use strict';
return function (config) {
var msg = '',
_config = jQuery.extend({
element: null,
message: '',
uniqueClass: 'required-unique'
}, config);
if (typeof _config.element === 'string') {
jQuery.validator.addMethod(
_config.element,
function (value, element) {
var inputs = jQuery(element)
.closest('table')
.find('.' + _config.uniqueClass + ':visible'),
valuesHash = {},
isValid = true,
duplicates = [];
inputs.each(function (el) {
var inputValue = inputs[el].value;
if (typeof valuesHash[inputValue] !== 'undefined') {
isValid = false;
duplicates.push(inputValue);
}
valuesHash[inputValue] = el;
});
if (!isValid) {
msg = _config.message.replace('%1', duplicates.join(', '));
}
return isValid;
},
msg
);
}
};
});
@@ -10,11 +10,17 @@ define([ | |||
'use strict'; | |||
|
|||
return function (config) { |
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.
@PieterCappelle It would be nice if you will cover this changes with JS tests.
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.
Do you have any guide to create this, never did this before. Sorry.
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.
@PieterCappelle Here is a doc and also you can see in dev/tests/js/jasmine/tests already created tests. If you will have some additional question contact me directly.
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.
@omiroshnichenko I tried this but it's to complex for me at this moment. I don't even get how I need to make the file structure. Do I need to follow the exact path as in the module directory? Other modules use custom paths and are ignore the path of the module.
Replied to all your comments @omiroshnichenko. Let me know if I can help. |
…10213 - Fixes according to the test results
[EngCom] Public Pull Requests - MAGETWO-70817: remove redundant else and use strict check #10271 - MAGETWO-70787: update phpserver to support versioned static urls #10250 - MAGETWO-70764: Fix overwrite default value image/file with NULL #10253 - MAGETWO-70761: Show values that are duplicate in attribute error msg #10213 - MAGETWO-70758: Fix for #4530 $product->getRatingSummary() always returns null […] #10248 - MAGETWO-70706: simplify product lists #2 #9019 - MAGETWO-70669: Fix fatal errors with deleteOptionsAndSelections #7711 - MAGETWO-70464: Fix shipping address can use for billing #10130 - MAGETWO-69913: magento/magento2 #9196 - Products ordered report doesn't show simple (child) products of configurable products #9908
@magento-team This PR isn't included in 2.2 Should it be backported? |
When you add values to some attribute it's possible you have created duplicated values. If you want to save that attribute at Stores > Attributes > Products you will see the error messagee "The value of Admin must be unique." but that error message is not telling you which value is not unique.
This PR shows which values are duplicated so you easily update/remove the values so you can pass the error. Let me know if I need to modify something because this is first PR.
Reproduce
Contribution checklist