From 9b5d8b8a01c3c5f96db845718c3610a2914caa35 Mon Sep 17 00:00:00 2001 From: Molkobain Date: Fri, 14 Dec 2018 11:11:59 +0100 Subject: [PATCH] =?UTF-8?q?N=C2=B0931=20Fix=20bug=20when=20max=20allowed?= =?UTF-8?q?=20items=20set=20to=201?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/ormset.class.inc.php | 2 +- js/jquery.itop-set-widget.js | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/core/ormset.class.inc.php b/core/ormset.class.inc.php index 98ac2cb8f..9879d8b49 100644 --- a/core/ormset.class.inc.php +++ b/core/ormset.class.inc.php @@ -264,7 +264,7 @@ class ormSet */ public function Add($oItem) { - if (($this->iLimit != 0) && ($this->Count() === $this->iLimit)) + if (($this->iLimit != 0) && ($this->Count() > $this->iLimit)) { throw new CoreException("Maximum number of items ({$this->iLimit}) reached for {$this->sClass}:{$this->sAttCode}"); } diff --git a/js/jquery.itop-set-widget.js b/js/jquery.itop-set-widget.js index 1c0e32c77..1d054c4e9 100644 --- a/js/jquery.itop-set-widget.js +++ b/js/jquery.itop-set-widget.js @@ -278,6 +278,13 @@ $.widget('itop.set_widget', } } + // When only one item allowed, selectize doesn't trigger the _onTagRemove callback so we have to clean ourselves. + if((this.maxItemsAllowed === 1) && (this.originalValue.length > 0)) { + if(setItemCode !== this.originalValue[0]) { + this.setItemsCodesStatus[this.originalValue[0]] = this.STATUS_REMOVED; + } + } + this.refresh(); },