Commit d1cb246f authored by colemanw's avatar colemanw
Browse files

Support is_primary fields and boolean options.

Civi 5.23 changes boolean options to be real true and false instead of '1' and '0'
so added version bump to keep in step.
parent 7afec9d2
......@@ -14,14 +14,16 @@
var ts = $scope.ts = CRM.ts('afform'),
closestController = $($el).closest('[af-fieldset],[af-join],[af-repeat-item]'),
afForm = ctrls[0],
boolOptions = [{key: '1', label: ts('Yes')}, {key: '0', label: ts('No')}];
boolOptions = [{key: true, label: ts('Yes')}, {key: false, label: ts('No')}],
// Only used for is_primary radio button
noOptions = [{key: true, label: ''}];
$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 || boolOptions;
return $scope.defn.options || ($scope.fieldName === 'is_primary' && $scope.defn.input_type === 'Radio' ? noOptions : boolOptions);
};
$scope.select2Options = function() {
......@@ -32,6 +34,23 @@
};
};
// is_primary field - watch others in this afRepeat block to ensure only one is selected
if ($scope.fieldName === 'is_primary' && 'repeatIndex' in $scope.dataProvider) {
$scope.$watch('dataProvider.afRepeat.getEntityController().getData()', function (items, prev) {
var index = $scope.dataProvider.repeatIndex;
// Set first item to primary if there isn't a primary
if (items && !index && !_.find(items, 'is_primary')) {
$scope.dataProvider.getFieldData().is_primary = true;
}
// Set this item to not primary if another has been selected
if (items && prev && items.length === prev.length && items[index].is_primary && prev[index].is_primary &&
_.filter(items, 'is_primary').length > 1
) {
$scope.dataProvider.getFieldData().is_primary = false;
}
}, true);
}
// ChainSelect - watch control field & reload options as needed
if ($scope.defn.input_type === 'ChainSelect') {
$scope.$watch('dataProvider.getFieldData()[defn.input_attrs.controlField]', function(val) {
......
......@@ -59,7 +59,8 @@
restrict: 'A',
require: ['afRepeatItem', '^^afRepeat'],
bindToController: {
item: '=afRepeatItem'
item: '=afRepeatItem',
repeatIndex: '='
},
link: function($scope, $el, $attr, ctrls) {
var self = ctrls[0];
......
<div af-repeat-item="item" ng-repeat="item in getItems()">
<div af-repeat-item="item" repeat-index="$index" ng-repeat="item in getItems()">
<ng-transclude />
<button crm-icon="fa-ban" class="btn btn-xs af-repeat-remove-btn" ng-if="canRemove()" ng-click="removeItem($index)"></button>
</div>
......
......@@ -4,4 +4,4 @@
<label for="{{ fieldId + opt.key }}">{{ opt.label }}</label>
</li>
</ul>
<input type="checkbox" ng-if="!defn.options" id="{{ fieldId }}" ng-model="dataProvider.getFieldData()[fieldName]" ng-true-value="'1'" ng-false-value="'0'" />
<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]" value="{{ opt.key }}" />
<input class="crm-form-radio" type="radio" ng-model="dataProvider.getFieldData()[fieldName]" ng-value="opt.key" />
{{ opt.label }}
</label>
<div class="af-container af-layout-inline">
<af-field name="street_address" />
<af-field name="location_type_id" />
<af-field name="is_primary" />
</div>
<div class="af-container af-layout-inline">
<af-field name="city" />
......
<div class="af-container af-layout-inline">
<af-field name="email" />
<af-field name="location_type_id" />
<af-field name="is_primary" />
</div>
......@@ -2,4 +2,5 @@
<af-field name="name" />
<af-field name="location_type_id" />
<af-field name="provider_id" />
<af-field name="is_primary" />
</div>
......@@ -2,4 +2,5 @@
<af-field name="phone" />
<af-field name="location_type_id" />
<af-field name="phone_type_id" />
<af-field name="is_primary" />
</div>
......@@ -15,10 +15,10 @@
<url desc="Licensing">http://www.gnu.org/licenses/agpl-3.0.html</url>
</urls>
<releaseDate>2020-01-09</releaseDate>
<version>0.4</version>
<version>0.5</version>
<develStage>alpha</develStage>
<compatibility>
<ver>5.22</ver>
<ver>5.23</ver>
</compatibility>
<requires>
<ext version="~4.5">org.civicrm.api4</ext>
......
......@@ -15,10 +15,10 @@
<url desc="Licensing">http://www.gnu.org/licenses/agpl-3.0.html</url>
</urls>
<releaseDate>2020-01-09</releaseDate>
<version>0.4</version>
<version>0.5</version>
<develStage>alpha</develStage>
<compatibility>
<ver>5.22</ver>
<ver>5.23</ver>
</compatibility>
<comments>Drag-n-drop form builder for CiviCRM Afforms.</comments>
<requires>
......
......@@ -15,10 +15,10 @@
<url desc="Licensing">http://www.gnu.org/licenses/agpl-3.0.html</url>
</urls>
<releaseDate>2020-01-09</releaseDate>
<version>0.4</version>
<version>0.5</version>
<develStage>alpha</develStage>
<compatibility>
<ver>5.22</ver>
<ver>5.23</ver>
</compatibility>
<requires>
<ext>org.civicrm.afform</ext>
......
......@@ -15,10 +15,10 @@
<url desc="Licensing">http://www.gnu.org/licenses/agpl-3.0.html</url>
</urls>
<releaseDate>2020-01-09</releaseDate>
<version>0.4</version>
<version>0.5</version>
<develStage>alpha</develStage>
<compatibility>
<ver>5.22</ver>
<ver>5.23</ver>
</compatibility>
<requires>
<ext>org.civicrm.afform</ext>
......
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