WCF.System.Event.addListener('com.woltlab.wcf.redactor2', 'reset_' + editorId, this._reset.bind(this));
WCF.System.Event.addListener('com.woltlab.wcf.redactor2', 'submit_' + editorId, this._submit.bind(this));
+ WCF.System.Event.addListener('com.woltlab.wcf.redactor2', 'validate_' + editorId, this._validate.bind(this));
}
else {
this._container.closest('form').submit($.proxy(this._submit, this));
require(['WoltLab/WCF/Date/Picker'], (function(UiDatePicker) {
UiDatePicker.clear('pollEndTime_' + this._editorId);
}).bind(this));
+ },
+
+ _validate: function(data) {
+ var question = elById('pollQuestion_' + this._editorId);
+ if (question.value.trim() === '') {
+ // no question provided, ignore
+ return;
+ }
+
+ // get options
+ var hasOptions = false;
+ elBySelAll('li input[type="text"]', this._container[0], function(input) {
+ if (input.value.trim() !== '') {
+ hasOptions = true;
+ }
+ });
+
+ if (hasOptions === false) {
+ data.api.throwError(this._container[0], WCF.Language.get('wcf.global.form.error.empty'));
+ data.valid = false;
+ }
}
});
var id = this._getEditorId();
EventHandler.fire('com.woltlab.wcf.redactor2', 'getText_' + id, parameters.data);
+
+ if (!this._validate(parameters)) {
+ // validation failed
+ return;
+ }
+
EventHandler.fire('com.woltlab.wcf.redactor2', 'submit_' + id, parameters);
Ajax.api(this, {
this._hideEditor();
},
+ /**
+ * Validates the message and invokes listeners to perform additional validation.
+ *
+ * @param {Object} parameters request parameters
+ * @return {boolean} validation result
+ * @protected
+ */
+ _validate: function(parameters) {
+ // remove all existing error elements
+ var errorMessages = elByClass('innerError', this._activeElement);
+ while (errorMessages.length) {
+ elRemove(errorMessages[0]);
+ }
+
+ var data = {
+ api: this,
+ parameters: parameters,
+ valid: true
+ };
+
+ EventHandler.fire('com.woltlab.wcf.redactor2', 'validate_' + this._getEditorId(), data);
+
+ return (data.valid !== false);
+ },
+
+ /**
+ * Throws an error by adding an inline error to target element.
+ *
+ * @param {Element} element erroneous element
+ * @param {string} message error message
+ */
+ throwError: function(element, message) {
+ var error = elCreate('small');
+ error.className = 'innerError';
+ error.textContent = message;
+
+ DomUtil.insertAfter(error, element);
+ },
+
/**
* Shows the update message.
*
// remove all existing error elements
var errorMessages = elByClass('innerError', this._container);
while (errorMessages.length) {
- errorMessages[0].parentNode.removeChild(errorMessages[0]);
+ elRemove(errorMessages[0]);
}
// check if editor contains actual content
}
var data = {
- 'api': this,
- 'editor': this._getEditor(),
- 'message': this._getEditor().code.get(),
- 'valid': true
+ api: this,
+ editor: this._getEditor(),
+ message: this._getEditor().code.get(),
+ valid: true
};
EventHandler.fire('com.woltlab.wcf.redactor2', 'validate_text', data);