I am currently using clientside_validation with clientside_validation_states to validate conditionally required fields.
The issue I am experiencing is when the conditionally required element is invalid (empty), it is showing the generic "This field is required" (from jQuery.validation defaults) instead of using a message that is typically seen (and shows on all other, non-conditionally required fields) - for example, "First Name field is required".
I am using a custom errorPlacement method, but I'm not sure that it matters:
// custom error placement
Drupal.clientsideValidation.prototype.replaceLabel = function (error, element) {
var label, origLabel;
var wrapperClass = 'formReplacedLabel';
var WrapperEl = 'span';
label = element.siblings('label');
if (label.find('.form-replaced-label').length === 0) {
label.wrapInner("<span class='form-replaced-label'></span>");
}
label.addClass('labelError');
label.prepend(error);
};
So, the error being passed (for the states dependent control) to the custom errorPlacement method is just the default $.validator.messages.required
instead of what is passed for the other controls. I can't just change .messages.required
to something that is for this field specifically either, as I have several forms with state dependent fields.
I have attached an animated gif that I think can explain the issue better than I do.