Commit 7afec9d2 authored by colemanw's avatar colemanw
Browse files

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.
parent b0de171a
......@@ -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() {
......
<ul class="crm-checkbox-list" id="{{ fieldId }}" ng-if="defn.options">
<li ng-repeat="opt in defn.options" >
<li ng-repeat="opt in defn.options track by opt.key" >
<input type="checkbox" checklist-model="dataProvider.getFieldData()[fieldName]" id="{{ fieldId + opt.key }}" checklist-value="opt.key" />
<label for="{{ fieldId + opt.key }}">{{ opt.label }}</label>
</li>
......
<label ng-repeat="opt in getOptions()" >
<label ng-repeat="opt in getOptions() track by opt.key" >
<input class="crm-form-radio" type="radio" ng-model="dataProvider.getFieldData()[fieldName]" value="{{ opt.key }}" />
{{ opt.label }}
</label>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment