Skip to content

Commit 05b2031

Browse files
authored
Merge pull request #11 from dof-dss/development
Unity modules release
2 parents f71205c + d915e14 commit 05b2031

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* @file
3+
* Attaches behaviors for the Clientside Validation jQuery module.
4+
*/
5+
6+
(function ($, drupalSettings) {
7+
8+
'use strict';
9+
10+
// Disable clientside validation for webforms submitted using Ajax.
11+
// This prevents Computed elements with Ajax from breaking.
12+
// @see
13+
// \Drupal\clientside_validation_jquery\Form\ClientsideValidationjQuerySettingsForm
14+
drupalSettings.clientside_validation_jquery.validate_all_ajax_forms = 0;
15+
16+
/**
17+
* Add .cv-validate-before-ajax to all webform submit buttons.
18+
*
19+
* @type {Drupal~behavior}
20+
*/
21+
Drupal.behaviors.errorMessageFixAjax = {
22+
attach: function (context) {
23+
$('form.search-form--site .form-actions .js-form-submit')
24+
.once('error-message-fix-ajax')
25+
.addClass('cv-validate-before-ajax');
26+
}
27+
};
28+
29+
$(document).once('errormessage-fix').on('cv-jquery-validate-options-update', function (event, options) {
30+
options.errorElement = 'p';
31+
options.showErrors = function (errorMap, errorList) {
32+
// Show errors using defaultShowErrors().
33+
this.defaultShowErrors();
34+
35+
// Add '.form-item--error-message' class to all errors.
36+
$(this.currentForm).find('strong.error').addClass('form-item--error-message');
37+
38+
};
39+
});
40+
41+
})(jQuery, drupalSettings);

unity_common/unity_common.libraries.yml

+6
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,9 @@ link_manager:
44
dependencies:
55
- core/jquery
66
- core/drupal
7+
unity_common_validation.ife:
8+
version: VERSION
9+
js:
10+
js/unity-common-validation.ife.js: { weight: -1 }
11+
dependencies:
12+
- clientside_validation_jquery/cv.jquery.validate.ife

unity_common/unity_common.module

+6
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ function unity_common_form_alter(&$form, FormStateInterface $form_state, $form_i
5353
);
5454
}
5555
}
56+
57+
if ($form['#id'] == 'views-exposed-form-search-site-search' || $form['#id'] == 'views-exposed-form-search-search-page') {
58+
if (\Drupal::moduleHandler()->moduleExists('inline_form_errors')) {
59+
$form['#attached']['library'][] = 'unity_common/unity_common_validation.ife';
60+
}
61+
}
5662
}
5763

5864
/**

0 commit comments

Comments
 (0)