From 810afdaf5a429468d31b09ae5a7f995dd11568f8 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 21 Feb 2021 12:28:25 +0300 Subject: [PATCH] prevent creation of filter rules matching no feeds --- classes/pref/filters.php | 2 +- js/form/ValidationMultiSelect.js | 20 ++++++++++++++++++++ js/prefs.js | 1 + js/tt-rss.js | 1 + 4 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 js/form/ValidationMultiSelect.js diff --git a/classes/pref/filters.php b/classes/pref/filters.php index c00e52bde..9388cc8d7 100755 --- a/classes/pref/filters.php +++ b/classes/pref/filters.php @@ -695,7 +695,7 @@ class Pref_Filters extends Handler_Protected { $feed_ids = explode(",", clean($_REQUEST["ids"])); print json_encode([ - "multiselect" => $this->_feed_multi_select("feed_id", $feed_ids, 'style="width : 540px; height : 300px" dojoType="dijit.form.MultiSelect"') + "multiselect" => $this->_feed_multi_select("feed_id", $feed_ids, 'required="1" style="width : 540px; height : 300px" dojoType="fox.form.ValidationMultiSelect"') ]); } diff --git a/js/form/ValidationMultiSelect.js b/js/form/ValidationMultiSelect.js new file mode 100644 index 000000000..4e7263c61 --- /dev/null +++ b/js/form/ValidationMultiSelect.js @@ -0,0 +1,20 @@ +/* global define */ + +// only supports required for the time being +// TODO: maybe show dojo native error message? i dunno +define(["dojo/_base/declare", "dojo/_base/lang", "dijit/form/MultiSelect", ], + function(declare, lang, MultiSelect) { + + return declare('fox.form.ValidationMultiSelect', [MultiSelect], { + constructor: function(params){ + this.constraints = {}; + this.baseClass += ' dijitValidationMultiSelect'; + }, + validate: function(/*Boolean*/ isFocused){ + if (this.required && this.attr('value').length == 0) + return false; + + return true; + }, + }) + }); diff --git a/js/prefs.js b/js/prefs.js index a23a74856..8f4f45700 100755 --- a/js/prefs.js +++ b/js/prefs.js @@ -53,6 +53,7 @@ require(["dojo/_base/kernel", "fox/PrefLabelTree", "fox/Toolbar", "fox/SingleUseDialog", + "fox/form/ValidationMultiSelect", "fox/form/ValidationTextArea", "fox/form/Select", "fox/form/ComboButton", diff --git a/js/tt-rss.js b/js/tt-rss.js index 8d7dd00a6..4a7f2e643 100644 --- a/js/tt-rss.js +++ b/js/tt-rss.js @@ -51,6 +51,7 @@ require(["dojo/_base/kernel", "fox/FeedTree", "fox/Toolbar", "fox/SingleUseDialog", + "fox/form/ValidationMultiSelect", "fox/form/ValidationTextArea", "fox/form/Select", "fox/form/ComboButton",