debian-mirror-gitlab/app/assets/javascripts/emoji/no_emoji_validator.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

34 lines
938 B
JavaScript
Raw Normal View History

2019-07-07 11:18:12 +05:30
import emojiRegex from 'emoji-regex';
2020-01-01 13:55:28 +05:30
import { __ } from '~/locale';
2019-09-04 21:01:54 +05:30
import InputValidator from '../validators/input_validator';
2019-07-07 11:18:12 +05:30
2019-09-04 21:01:54 +05:30
export default class NoEmojiValidator extends InputValidator {
2019-07-07 11:18:12 +05:30
constructor(opts = {}) {
2019-09-04 21:01:54 +05:30
super();
2019-07-07 11:18:12 +05:30
const container = opts.container || '';
this.noEmojiEmelents = document.querySelectorAll(`${container} .js-block-emoji`);
2021-03-08 18:12:59 +05:30
this.noEmojiEmelents.forEach((element) =>
2019-07-07 11:18:12 +05:30
element.addEventListener('input', this.eventHandler.bind(this)),
);
}
eventHandler(event) {
this.inputDomElement = event.target;
this.inputErrorMessage = this.inputDomElement.nextSibling;
const { value } = this.inputDomElement;
2019-09-04 21:01:54 +05:30
this.errorMessage = __('Invalid input, please avoid emojis');
2019-07-07 11:18:12 +05:30
this.validatePattern(value);
this.setValidationStateAndMessage();
}
validatePattern(value) {
const pattern = emojiRegex();
2019-09-04 21:01:54 +05:30
this.invalidInput = new RegExp(pattern).test(value);
2019-07-07 11:18:12 +05:30
}
}