Sync client-side poll validation with server-side validation
authorMatthias Schmidt <gravatronics@live.com>
Thu, 10 Jun 2021 07:01:57 +0000 (09:01 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Thu, 10 Jun 2021 07:01:57 +0000 (09:01 +0200)
`PollManager` marks an empty question field as empty if poll options are given, while `WCF.Poll.Management` aborted validation once the question field is empty, no matter whether options are given or not.

wcfsetup/install/files/js/WCF.Poll.js

index 290423d6eae1a199106274a793129b798f4bd389..93edea6b9df824d2e8791e5a1273f0e20f78319e 100644 (file)
@@ -282,12 +282,6 @@ if (COMPILER_TARGET_DEFAULT) {
                },
                
                _validate: function (data) {
-                       var question = elById('pollQuestion_' + this._editorId);
-                       if (question.value.trim() === '') {
-                               // no question provided, ignore
-                               return;
-                       }
-                       
                        // get options
                        var count = 0;
                        elBySelAll('li input[type="text"]', this._container[0], function (input) {
@@ -296,6 +290,18 @@ if (COMPILER_TARGET_DEFAULT) {
                                }
                        });
                        
+                       var question = elById('pollQuestion_' + this._editorId);
+                       if (question.value.trim() === '') {
+                               if (count === 0) {
+                                       // no question and no options provided, ignore
+                                       return;
+                               }
+                               else {
+                                       data.api.throwError(question, WCF.Language.get('wcf.global.form.error.empty'));
+                                       data.valid = false;
+                               }
+                       }
+                       
                        if (count === 0) {
                                data.api.throwError(this._container[0], WCF.Language.get('wcf.global.form.error.empty'));
                                data.valid = false;