Skip to content

Commit

Permalink
Afform - Allow search range by postal code
Browse files Browse the repository at this point in the history
Search display forms only allow numeric fields to be a search range,
but postal code is an exception (it's stored as a string but is numeric in some locales)
  • Loading branch information
colemanw committed Apr 5, 2021
1 parent d4e2c9f commit 0a8585d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,16 @@
};

this.canBeRange = function() {
// Range search only makes sense for search display forms
return this.isSearch() &&
!ctrl.getDefn().input_attrs.multiple &&
_.includes(['Date', 'Timestamp', 'Integer', 'Float'], ctrl.getDefn().data_type) &&
_.includes(['Date', 'Number', 'Select'], $scope.getProp('input_type'));
// Hack for postal code which is not stored as a number but can act like one
(ctrl.node.name.substr(-11) === 'postal_code' || (
// Multiselects cannot use range search
!ctrl.getDefn().input_attrs.multiple &&
// DataType & inputType must make sense for a range
_.includes(['Date', 'Timestamp', 'Integer', 'Float'], ctrl.getDefn().data_type) &&
_.includes(['Date', 'Number', 'Select'], $scope.getProp('input_type'))
));
};

this.canBeMultiple = function() {
Expand Down
7 changes: 6 additions & 1 deletion ext/afform/admin/ang/afGuiEditor/inputType/Text.html
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
<input autocomplete="off" class="form-control" ng-model="getSet('input_attrs.placeholder')" ng-model-options="{getterSetter: true}" type="text" title="{{:: ts('Click to add placeholder text') }}" />
<div class="form-inline">
<div class="form-group" ng-repeat="i in $ctrl.getRangeElements('Text')">
<span class="af-field-range-sep" ng-if="i">-</span>
<input autocomplete="off" class="form-control" ng-model="getSet('input_attrs.placeholder' + i)" ng-model-options="{getterSetter: true}" type="text" title="{{:: ts('Click to add placeholder text') }}"/>
</div>
</div>
7 changes: 6 additions & 1 deletion ext/afform/core/ang/af/fields/Text.html
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
<input class="form-control" type="text" id="{{:: fieldId }}" ng-model="dataProvider.getFieldData()[$ctrl.fieldName]" placeholder="{{:: $ctrl.defn.input_attrs.placeholder }}" >
<input ng-if=":: !$ctrl.defn.search_range" class="form-control" type="text" id="{{:: fieldId }}" ng-model="dataProvider.getFieldData()[$ctrl.fieldName]" placeholder="{{:: $ctrl.defn.input_attrs.placeholder }}" >
<div ng-if=":: $ctrl.defn.search_range" class="form-inline">
<input class="form-control" type="text" id="{{:: fieldId }}" ng-model="dataProvider.getFieldData()[$ctrl.fieldName]['>=']" placeholder="{{:: $ctrl.defn.input_attrs.placeholder }}" >
<span class="af-field-range-sep">-</span>
<input class="form-control" type="text" id="{{:: fieldId }}2" ng-model="dataProvider.getFieldData()[$ctrl.fieldName]['<=']" placeholder="{{:: $ctrl.defn.input_attrs.placeholder2 }}" >
</div>

0 comments on commit 0a8585d

Please sign in to comment.