Parsley data-parsley-error-message just presents global message within ul.parsley-errors-list
See original GitHub issueWhat kind of issue is this? (put ‘x’ between the square brackets)
-
Question. This issue tracker is not the place for questions. If you want to ask how to do something, or to understand why something isn’t working the way you expect it to, use http://stackoverflow.com/questions/ask . Provide working code, starting from http://codepen.io/marcandre/pen/jqbzyN?editors=101. We monitor the tag
parsley.js
. -
[x ] Bug report. If you’ve found a bug, you must provide a minimal example in a CodePen, starting from http://codepen.io/marcandre/pen/jqbzyN?editors=101 .
-
Feature Request. Make sure there’s no good way to do what you want first; consider asking on http://stackoverflow.com/questions/ask first.
See details here
I put together this small patch locally to allow the global message to take precedence over other messages:
diff --git a/vendor/assets/javascripts/parsley.js b/vendor/assets/javascripts/parsley.js
index d34a2f5..7838509 100644
--- a/vendor/assets/javascripts/parsley.js
+++ b/vendor/assets/javascripts/parsley.js
@@ -1030,9 +1030,10 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
},
_getErrorMessage: function _getErrorMessage(constraint) {
- var customConstraintErrorMessage = constraint.name + 'Message';
+ var customConstraintErrorMessage = this.options['errorMessage'] || this.options[constraint.name + 'Message'];
- if ('undefined' !== typeof this.options[customConstraintErrorMessage]) return window.Parsley.formatMessage(this.options[customConstraintErrorMessage], constraint.requirements);
+ if ('undefined' !== typeof customConstraintErrorMessage)
+ return window.Parsley.formatMessage(customConstraintErrorMessage, constraint.requirements);
return window.Parsley.getErrorMessage(constraint);
},
The order of options in the assignment to customConstraintErrorMessage
could be reversed if specific error messages should take precedence over global.
I am attempting to upgrade from Parsley v2.0.7; we have some poorly structured validations which specify both global and specific messages, but our tests assume global message has precedence since we had overridden ParsleyUI._getErrorMessage
. That override no longer works with v2.8 and looking at the docs it appeared as though the data-parsley-error-message
feature would work out-of-the-box. That’s how I wound up here.
Issue Analytics
- State:
- Created 6 years ago
- Comments:8
Top GitHub Comments
I’m afraid it won’t work. I’m sorry that Parsley object creation is a real kludge. I hope to fix it one day… In the meantime you can use another kludge instead:
window.ParsleyExtend._getErrorMessage = ...
(after loading Parsley).Correct on the docs. Priority is not specified.
WRT precedence, taking a closer look at the code I removed from our extensions:
I see that we had given priority to
customConstraintErrorMessage
. So the test failures must’ve been just because I ran the tests after I’d removed the code above from our extensions, but before adding it back via the patch posted previously.I confirmed this by changing my current
_getErrorMessages
to:and rerunning our tests. They pass.
Given this, I concur with your statement “
customConstraintErrorMessage
should get priority, with errorMessage being a catch all for other types…” and we actually have no issue withcustomConstraintErrorMessage
taking higher priority.