$getFieldParams = [
'checkPermissions' => FALSE,
'includeCustom' => TRUE,
- 'loadOptions' => TRUE,
+ 'loadOptions' => ['id', 'label'],
'action' => 'create',
'select' => ['name', 'label', 'input_type', 'input_attrs', 'required', 'options', 'help_pre', 'help_post', 'serialize', 'data_type'],
'where' => [['input_type', 'IS NOT NULL']],
],
];
- // Reformat options
- // TODO: Teach the api to return options in this format
- foreach ($data['entities'] as $entityName => $entity) {
- foreach ($entity['fields'] as $name => $field) {
- if (!empty($field['options'])) {
- $data['entities'][$entityName]['fields'][$name]['options'] = CRM_Utils_Array::makeNonAssociative($field['options'], 'key', 'label');
- }
- else {
- unset($data['entities'][$entityName]['fields'][$name]['options']);
- }
- }
- }
-
$data['styles'] = [
'default' => E::ts('Default'),
'primary' => E::ts('Primary'),
this.$onInit = function() {
$scope.options = JSON.parse(angular.toJson(ctrl.field.getOptions()));
- var optionKeys = _.map($scope.options, 'key');
+ var optionKeys = _.map($scope.options, 'id');
$scope.deletedOptions = _.filter(JSON.parse(angular.toJson(ctrl.field.getDefn().options || [])), function (item) {
- return !_.contains(optionKeys, item.key);
+ return !_.contains(optionKeys, item.id);
});
$scope.originalLabels = _.transform(ctrl.field.getDefn().options || [], function (originalLabels, item) {
- originalLabels[item.key] = item.label;
+ originalLabels[item.id] = item.label;
}, {});
};
</div>
<ul ui-sortable="{connectWith: '.af-gui-edit-options-deleted', cancel: 'input,textarea,button,select,option,a,[contenteditable]'}" ng-model="options" class="af-gui-edit-options-enabled">
<li ng-repeat="option in options">
- <div af-gui-editable ng-model="option.label" default-value="originalLabels[option.key]" >{{ option.label }}</div>
+ <div af-gui-editable ng-model="option.label" default-value="originalLabels[option.id]" >{{ option.label }}</div>
<button type="button" class="btn btn-danger-outline btn-xs pull-right" ng-click="deleteOption(option, $index)" title="{{:: ts('Remove option') }}">
<i class="crm-i fa-trash"></i>
</button>
$el.crmEntityRef({entity: field.fk_entity, select:{multiple: multi}});
} else if (field.options) {
var options = _.transform(field.options, function(options, val) {
- options.push({id: val.key, text: val.label});
+ options.push({id: val.id, text: val.label});
}, []);
$el.select2({data: options, multiple: multi});
} else if (dataType === 'Boolean') {
$scope.editingOptions = false;
var yesNo = [
- {key: '1', label: ts('Yes')},
- {key: '0', label: ts('No')}
+ {id: '1', label: ts('Yes')},
+ {id: '0', label: ts('No')}
];
this.$onInit = function() {
'action' => 'create',
'where' => [['name', '=', $afField->getAttribute('name')]],
'select' => ['label', 'input_type', 'input_attrs', 'options'],
- 'loadOptions' => TRUE,
+ 'loadOptions' => ['id', 'label'],
];
if (in_array($entityType, CRM_Contact_BAO_ContactType::basicTypes(TRUE))) {
$params['values'] = ['contact_type' => $entityType];
// If it's not an object, don't mess with it.
continue;
}
- // TODO: Teach the api to return options in this format
- if (!empty($fieldInfo['options'])) {
- $fieldInfo['options'] = CRM_Utils_Array::makeNonAssociative($fieldInfo['options'], 'key', 'label');
- }
// Default placeholder for select inputs
if ($fieldInfo['input_type'] === 'Select') {
$fieldInfo['input_attrs'] = ($fieldInfo['input_attrs'] ?? []) + ['placeholder' => ts('Select')];
var ts = $scope.ts = CRM.ts('afform'),
closestController = $($el).closest('[af-fieldset],[af-join],[af-repeat-item]'),
afForm = ctrls[0],
- boolOptions = [{key: true, label: ts('Yes')}, {key: false, label: ts('No')}],
+ boolOptions = [{id: true, label: ts('Yes')}, {id: false, label: ts('No')}],
// Only used for is_primary radio button
- noOptions = [{key: true, label: ''}];
+ noOptions = [{id: true, label: ''}];
$scope.dataProvider = closestController.is('[af-repeat-item]') ? ctrls[3] : ctrls[2] || ctrls[1];
$scope.fieldId = afForm.getFormMeta().name + '-' + $scope.fieldName + '-' + id++;
$scope.select2Options = function() {
return {
results: _.transform($scope.getOptions(), function(result, opt) {
- result.push({id: opt.key, text: opt.label});
+ result.push({id: opt.id, text: opt.label});
}, [])
};
};
var params = {
where: [['name', '=', $scope.fieldName]],
select: ['options'],
- loadOptions: true,
+ loadOptions: ['id', 'label'],
values: {}
};
params.values[$scope.defn.input_attrs.controlField] = val;
crmApi4($scope.dataProvider.getEntityType(), 'getFields', params, 0)
.then(function(data) {
- $scope.defn.options.length = 0;
- _.transform(data.options, function(options, label, key) {
- options.push({key: key, label: label});
- }, $scope.defn.options);
+ $scope.defn.options = data.options;
});
}
});
<ul class="crm-checkbox-list" id="{{ fieldId }}" ng-if="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 ng-repeat="opt in defn.options track by opt.id" >
+ <input type="checkbox" checklist-model="dataProvider.getFieldData()[fieldName]" id="{{ fieldId + opt.id }}" checklist-value="opt.id" />
+ <label for="{{ fieldId + opt.id }}">{{ opt.label }}</label>
</li>
</ul>
<input type="checkbox" ng-if="!defn.options" id="{{ fieldId }}" ng-model="dataProvider.getFieldData()[fieldName]" />
-<label ng-repeat="opt in getOptions() track by opt.key" >
- <input class="crm-form-radio" type="radio" ng-model="dataProvider.getFieldData()[fieldName]" ng-value="opt.key" />
+<label ng-repeat="opt in getOptions() track by opt.id" >
+ <input class="crm-form-radio" type="radio" ng-model="dataProvider.getFieldData()[fieldName]" ng-value="opt.id" />
{{ opt.label }}
</label>
<af-field name="first_name" />
<af-field name="last_name" />
</div>
- <af-field name="gender_id" defn="{options: [{key: 1, label: 'Girl'}, {key: 2, label: 'Boy'}, {key: 3, label: 'Other'}]}"/>
+ <af-field name="gender_id" defn="{options: [{id: 1, label: 'Girl'}, {id: 2, label: 'Boy'}, {id: 3, label: 'Other'}]}"/>
<af-field name="constituent_information.Marital_Status" />
<af-field name="constituent_information.Marriage_Date" />
<af-field name="constituent_information.Most_Important_Issue" />