crmAutocomplete - Fix endless loop (again)
authorcolemanw <coleman@civicrm.org>
Thu, 29 Jun 2023 17:07:19 +0000 (13:07 -0400)
committercolemanw <coleman@civicrm.org>
Fri, 30 Jun 2023 16:46:00 +0000 (12:46 -0400)
This regressed in 65a6ae6b9228ad945b0f2dc9b80886468098555f because the comparison
needs to equivocate numbers and numeric strings.

Update ang/crmUi.js

Co-authored-by: Rich Lott <artfulrobot@users.noreply.github.com>
ang/crmUi.js

index 0f3019eb0a2029fa311869b8dd89f4efcb77c7cb..718bf22b0a71aeb2f70eb59bf8ced73b65c99105 100644 (file)
             ctrl.ngModel.$render = function() {
               // Trigger change so the Select2 renders the current value,
               // but only if the value has actually changed (to avoid recursion)
-              if (!angular.equals(ctrl.ngModel.$viewValue || '', element.val())) {
-                element.val(ctrl.ngModel.$viewValue || '').change();
+              // We need to coerce null|false in the model to '' and numbers to strings.
+              // We need 0 not to be equivalent to null|false|''
+              const newValue = (ctrl.ngModel.$viewValue === null || ctrl.ngModel.$viewValue === undefined || ctrl.ngModel.$viewValue === false) ? '' : ctrl.ngModel.$viewValue.toString();
+              if (newValue !== element.val().toString()) {
+                element.val(newValue).change();
               }
             };