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(); },