Skip to content

Commit

Permalink
Add custom field type Hidden
Browse files Browse the repository at this point in the history
  • Loading branch information
colemanw committed Sep 1, 2023
1 parent 2880b5e commit 834ed31
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 6 deletions.
8 changes: 8 additions & 0 deletions CRM/Core/BAO/CustomField.php
Expand Up @@ -1075,6 +1075,10 @@ public static function addQuickFormElement(

$qf->assign('customUrls', $customUrls);
break;

case 'Hidden':
$element = $qf->add('hidden', $elementName);
break;
}

switch ($field->data_type) {
Expand Down Expand Up @@ -1376,6 +1380,10 @@ private static function formatDisplayValue($value, $field, $entityId = NULL) {
$display = implode(', ', $values);
}
break;

case 'Hidden':
$display = '';
break;
}
return $display;
}
Expand Down
5 changes: 5 additions & 0 deletions CRM/Core/SelectValues.php
Expand Up @@ -219,6 +219,11 @@ public static function customHtmlType() {
'name' => 'Link',
'label' => ts('Link'),
],
[
'id' => 'Hidden',
'name' => 'Hidden',
'label' => ts('Hidden'),
],
];
}

Expand Down
8 changes: 4 additions & 4 deletions CRM/Custom/Form/Field.php
Expand Up @@ -58,10 +58,10 @@ class CRM_Custom_Form_Field extends CRM_Core_Form {
* @var array[]
*/
public static $_dataToHTML = [
'String' => ['Text', 'Select', 'Radio', 'CheckBox', 'Autocomplete-Select'],
'Int' => ['Text', 'Select', 'Radio'],
'Float' => ['Text', 'Select', 'Radio'],
'Money' => ['Text', 'Select', 'Radio'],
'String' => ['Text', 'Select', 'Radio', 'CheckBox', 'Autocomplete-Select', 'Hidden'],
'Int' => ['Text', 'Select', 'Radio', 'Hidden'],
'Float' => ['Text', 'Select', 'Radio', 'Hidden'],
'Money' => ['Text', 'Select', 'Radio', 'Hidden'],
'Memo' => ['TextArea', 'RichTextEditor'],
'Date' => ['Select Date'],
'Boolean' => ['Radio'],
Expand Down
1 change: 1 addition & 0 deletions Civi/Api4/Generic/BasicGetFieldsAction.php
Expand Up @@ -324,6 +324,7 @@ public function fields() {
'Email' => ts('Email'),
'EntityRef' => ts('Autocomplete Entity'),
'File' => ts('File'),
'Hidden' => ts('Hidden'),
'Location' => ts('Address Location'),
'Number' => ts('Number'),
'Radio' => ts('Radio Buttons'),
Expand Down
Expand Up @@ -181,6 +181,7 @@
return !(defn.options || defn.data_type === 'Boolean');

case 'DisplayOnly':
case 'Hidden':
return true;

default:
Expand Down
1 change: 1 addition & 0 deletions ext/afform/admin/ang/afGuiEditor/inputType/Hidden.html
@@ -0,0 +1 @@
<div class="form-inline"></div>
1 change: 1 addition & 0 deletions ext/afform/core/ang/af/fields/Hidden.html
@@ -0,0 +1 @@
<input type="hidden" id="{{:: fieldId }}" ng-model="getSetValue" ng-model-options="{getterSetter: true}" >
4 changes: 2 additions & 2 deletions templates/CRM/Custom/Form/Field.tpl
Expand Up @@ -270,7 +270,7 @@
}

if (_.includes(['String', 'Int', 'Float', 'Money'], dataType)) {
if (htmlType !== "Text") {
if (!['Text', 'Hidden'].includes(htmlType)) {
$("#showoption, #searchable", $form).show();
$("#hideDefault, #hideDesc, #searchByRange", $form).hide();
} else {
Expand All @@ -289,7 +289,7 @@
$("#showoption").hide();
}

if (_.includes(['String', 'Int', 'Float', 'Money'], dataType) && htmlType !== 'Text') {
if (_.includes(['String', 'Int', 'Float', 'Money'], dataType) && !['Text', 'Hidden'].includes(htmlType)) {
if (serialize) {
$('div[id^=checkbox]', '#optionField').show();
$('div[id^=radio]', '#optionField').hide();
Expand Down

0 comments on commit 834ed31

Please sign in to comment.