2019-07-07 11:18:12 +05:30
|
|
|
import { __ } from '~/locale';
|
|
|
|
import emojiRegex from 'emoji-regex';
|
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`);
|
|
|
|
|
|
|
|
this.noEmojiEmelents.forEach(element =>
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|