Fixed poll error handling
authorAlexander Ebert <ebert@woltlab.com>
Wed, 31 Aug 2016 09:43:17 +0000 (11:43 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Wed, 31 Aug 2016 09:43:23 +0000 (11:43 +0200)
com.woltlab.wcf/templates/__messageFormPollInline.tpl
wcfsetup/install/files/js/WCF.Poll.js

index b3465b05dc2c3a420a89b9245b3956191ad8c649..01f778c226163832bf0d745758d2e9fc4a1fa959 100644 (file)
@@ -4,7 +4,9 @@
                $(function() {
                        WCF.Language.addObject({
                                'wcf.poll.button.addOption': '{lang}wcf.poll.button.addOption{/lang}',
-                               'wcf.poll.button.removeOption': '{lang}wcf.poll.button.removeOption{/lang}'
+                               'wcf.poll.button.removeOption': '{lang}wcf.poll.button.removeOption{/lang}',
+                               'wcf.poll.endTime.error.notValid': '{lang}wcf.poll.endTime.error.notValid{/lang}',
+                               'wcf.poll.maxVotes.error.notValid': '{lang}wcf.poll.maxVotes.error.notValid{/lang}'
                        });
                        
                        new WCF.Poll.Management(
index 33667ce79027b4c92926d6defbc44dc7fb5af7e1..a8bfc328d0e3eee406e8c1fec0c50f5581555427 100644 (file)
@@ -276,17 +276,25 @@ WCF.Poll.Management = Class.extend({
                }
                
                // get options
-               var hasOptions = false;
+               var count = 0;
                elBySelAll('li input[type="text"]', this._container[0], function(input) {
                        if (input.value.trim() !== '') {
-                               hasOptions = true;
+                               count++;
                        }
                });
                
-               if (hasOptions === false) {
+               if (count === 0) {
                        data.api.throwError(this._container[0], WCF.Language.get('wcf.global.form.error.empty'));
                        data.valid = false;
                }
+               else {
+                       var pollMaxVotes = elById('pollMaxVotes_' + this._editorId);
+                       var num = ~~pollMaxVotes.value;
+                       if (num && num > count) {
+                               data.api.throwError(pollMaxVotes, WCF.Language.get('wcf.poll.maxVotes.error.notValid'));
+                               data.valid = false;
+                       }
+               }
        }
 });