Commit 3002a55c authored by peterhegman's avatar peterhegman

Pass error message props via JS instead of HAML

Move passing of `errorMessage` and `disallowedValueErrorMessage` to JS
instead of passing it via HAML data attributes
parent b6e9249a
...@@ -2,7 +2,7 @@ import Vue from 'vue'; ...@@ -2,7 +2,7 @@ import Vue from 'vue';
import { __, sprintf } from '~/locale'; import { __, sprintf } from '~/locale';
import CommaSeparatedListTokenSelector from '../components/comma_separated_list_token_selector.vue'; import CommaSeparatedListTokenSelector from '../components/comma_separated_list_token_selector.vue';
export default (el, placeholder, qaSelector) => { export default (el, props = {}, qaSelector) => {
// eslint-disable-next-line no-new // eslint-disable-next-line no-new
new Vue({ new Vue({
el, el,
...@@ -10,21 +10,14 @@ export default (el, placeholder, qaSelector) => { ...@@ -10,21 +10,14 @@ export default (el, placeholder, qaSelector) => {
CommaSeparatedListTokenSelector, CommaSeparatedListTokenSelector,
}, },
data() { data() {
const { const { hiddenInputId, labelId, regexValidator, disallowedValues } = document.querySelector(
hiddenInputId, this.$options.el,
labelId, ).dataset;
regexValidator,
disallowedValues,
errorMessage,
disallowedValueErrorMessage,
} = document.querySelector(this.$options.el).dataset;
return { return {
hiddenInputId, hiddenInputId,
labelId, labelId,
regexValidator, regexValidator,
errorMessage,
disallowedValueErrorMessage,
...(regexValidator ? { regexValidator: new RegExp(regexValidator) } : {}), ...(regexValidator ? { regexValidator: new RegExp(regexValidator) } : {}),
...(disallowedValues ? { disallowedValues: JSON.parse(disallowedValues) } : {}), ...(disallowedValues ? { disallowedValues: JSON.parse(disallowedValues) } : {}),
}; };
...@@ -39,9 +32,7 @@ export default (el, placeholder, qaSelector) => { ...@@ -39,9 +32,7 @@ export default (el, placeholder, qaSelector) => {
ariaLabelledby: this.labelId, ariaLabelledby: this.labelId,
regexValidator: this.regexValidator, regexValidator: this.regexValidator,
disallowedValues: this.disallowedValues, disallowedValues: this.disallowedValues,
errorMessage: this.errorMessage, ...props,
disallowedValueErrorMessage: this.disallowedValueErrorMessage,
placeholder,
}, },
scopedSlots: { scopedSlots: {
'user-defined-token-content': ({ inputText: value }) => { 'user-defined-token-content': ({ inputText: value }) => {
......
...@@ -3,10 +3,14 @@ import initAccessRestrictionField from 'ee/groups/settings/access_restriction_fi ...@@ -3,10 +3,14 @@ import initAccessRestrictionField from 'ee/groups/settings/access_restriction_fi
import { __ } from '~/locale'; import { __ } from '~/locale';
document.addEventListener('DOMContentLoaded', () => { document.addEventListener('DOMContentLoaded', () => {
initAccessRestrictionField('.js-allowed-email-domains', __('Enter domain')); initAccessRestrictionField('.js-allowed-email-domains', {
placeholder: __('Enter domain'),
errorMessage: __('The domain you entered is misformatted.'),
disallowedValueErrorMessage: __('The domain you entered is not allowed.'),
});
initAccessRestrictionField( initAccessRestrictionField(
'.js-ip-restriction', '.js-ip-restriction',
__('Enter IP address range'), { placeholder: __('Enter IP address range') },
'ip_restriction_field', 'ip_restriction_field',
); );
}); });
...@@ -8,9 +8,7 @@ ...@@ -8,9 +8,7 @@
.js-allowed-email-domains{ data: { hidden_input_id: hidden_input_id, .js-allowed-email-domains{ data: { hidden_input_id: hidden_input_id,
label_id: label_id, label_id: label_id,
regex_validator: AllowedEmailDomain::VALID_DOMAIN_REGEX.source, regex_validator: AllowedEmailDomain::VALID_DOMAIN_REGEX.source,
disallowed_values: AllowedEmailDomain::RESERVED_DOMAINS.to_json, disallowed_values: AllowedEmailDomain::RESERVED_DOMAINS.to_json } }
error_message: _('The domain you entered is misformatted.'),
disallowed_value_error_message: _('The domain you entered is not allowed.') } }
= f.hidden_field :allowed_email_domains_list, id: hidden_input_id = f.hidden_field :allowed_email_domains_list, id: hidden_input_id
.form-text.text-muted .form-text.text-muted
- read_more_link = link_to(_('Read more'), help_page_path('user/group/index', anchor: 'allowed-domain-restriction-premium')) - read_more_link = link_to(_('Read more'), help_page_path('user/group/index', anchor: 'allowed-domain-restriction-premium'))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment