From 4e35388cb4e75d12d8805247a9e623680def3553 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Fri, 10 Jan 2020 12:59:49 -0500 Subject: [PATCH] More efficient select options handling The afField.getOptions function was causing infinite recursion by recreating the boolean options array every time. Passing this variable by refernce solves the problem, and adding "track by" to the ng-repeat follows best-practices for efficiency. --- ext/afform/core/ang/af/Field.js | 5 +++-- ext/afform/core/ang/af/fields/CheckBox.html | 2 +- ext/afform/core/ang/af/fields/Radio.html | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/ext/afform/core/ang/af/Field.js b/ext/afform/core/ang/af/Field.js index 554eb82218..e23beaefbd 100644 --- a/ext/afform/core/ang/af/Field.js +++ b/ext/afform/core/ang/af/Field.js @@ -13,14 +13,15 @@ link: function($scope, $el, $attr, ctrls) { var ts = $scope.ts = CRM.ts('afform'), closestController = $($el).closest('[af-fieldset],[af-join],[af-repeat-item]'), - afForm = ctrls[0]; + afForm = ctrls[0], + boolOptions = [{key: '1', label: ts('Yes')}, {key: '0', label: ts('No')}]; $scope.dataProvider = closestController.is('[af-repeat-item]') ? ctrls[3] : ctrls[2] || ctrls[1]; $scope.fieldId = afForm.getFormMeta().name + '-' + $scope.fieldName + '-' + id++; $el.addClass('af-field-type-' + _.kebabCase($scope.defn.input_type)); $scope.getOptions = function() { - return $scope.defn.options || [{key: '1', label: ts('Yes')}, {key: '0', label: ts('No')}]; + return $scope.defn.options || boolOptions; }; $scope.select2Options = function() { diff --git a/ext/afform/core/ang/af/fields/CheckBox.html b/ext/afform/core/ang/af/fields/CheckBox.html index be20b9efe5..de7d94c85f 100644 --- a/ext/afform/core/ang/af/fields/CheckBox.html +++ b/ext/afform/core/ang/af/fields/CheckBox.html @@ -1,5 +1,5 @@