add admin configuration to set the date defaults
authorKurund Jalmi <kurundjalmi@thirdsectordesign.org>
Fri, 3 Nov 2023 17:50:14 +0000 (17:50 +0000)
committerKurund Jalmi <kurundjalmi@thirdsectordesign.org>
Fri, 3 Nov 2023 17:50:14 +0000 (17:50 +0000)
ext/afform/admin/ang/afGuiEditor/elements/afGuiField-menu.html
ext/afform/admin/ang/afGuiEditor/elements/afGuiField.component.js

index 9c49cbcccdc757d1e28ce607fd22f63da932baf7..5f01636f58e76c958f4885879b9ba8b170ac4cd5 100644 (file)
     {{:: ts('Default value') }}
   </a>
 </li>
-<li ng-if="$ctrl.hasDefaultValue">
+<li ng-if="$ctrl.fieldDefn.input_type === 'Date' && $ctrl.hasDefaultValue">
+  <div ng-click="setDefaultDateType(); $event.stopPropagation(); $event.target.blur();" class="af-gui-field-select-in-dropdown form-inline">
+    <select class="form-control" ng-model="getSet('default_date_type')" ng-model-options="{getterSetter: true}">
+      <option value="fixed_date">{{:: ts('Fixed Date') }}</option>
+      <option value="current_date">{{:: ts('Current Date') }}</option>
+    </select>
+  </div>
+</li>
+<li ng-if="$ctrl.hasDefaultValue && $ctrl.defaultDateType !== 'current_date'">
   <form ng-click="$event.stopPropagation()" class="af-gui-field-select-in-dropdown form-inline">
     <input class="form-control" af-gui-field-value="$ctrl.fieldDefn" ng-model="getSet('afform_default')" ng-model-options="{getterSetter: true}" >
   </form>
index 1b9f03495dbe31eedbf325a9613e52228bd6e18d..ace876defb116c8e642478e0dc6ac2d5eacfed37 100644 (file)
           this.searchOperators = _.pick(this.searchOperators, ctrl.fieldDefn.operators);
         }
         setDateOptions();
+
+        if (ctrl.getDefn().input_type == 'Date' && !getSet('default_date_type')) {
+          ctrl.defaultDateType = getSet('default_date_type', 'fixed_date');
+        }
       };
 
       this.getFkEntity = function() {
         }
       };
 
+      $scope.setDefaultDateType = function() {
+        ctrl.defaultDateType = getSet('default_date_type');
+      };
+
       $scope.defaultValueContains = function(val) {
         val = '' + val;
         var defaultVal = getSet('afform_default');