Merge pull request #13252 from jmcclelland/issue586
[civicrm-core.git] / templates / CRM / Custom / Form / Field.tpl
CommitLineData
6a488035
TO
1{*
2 +--------------------------------------------------------------------+
fee14197 3 | CiviCRM version 5 |
6a488035 4 +--------------------------------------------------------------------+
6b83d5bd 5 | Copyright CiviCRM LLC (c) 2004-2019 |
6a488035
TO
6 +--------------------------------------------------------------------+
7 | This file is a part of CiviCRM. |
8 | |
9 | CiviCRM is free software; you can copy, modify, and distribute it |
10 | under the terms of the GNU Affero General Public License |
11 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
12 | |
13 | CiviCRM is distributed in the hope that it will be useful, but |
14 | WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
16 | See the GNU Affero General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU Affero General Public |
19 | License and the CiviCRM Licensing Exception along |
20 | with this program; if not, contact CiviCRM LLC |
21 | at info[AT]civicrm[DOT]org. If you have questions about the |
22 | GNU Affero General Public License or the licensing of CiviCRM, |
23 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
24 +--------------------------------------------------------------------+
25*}
6a488035 26<div class="crm-block crm-form-block crm-custom-field-form-block">
9edef7c7
CW
27 <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="top"}</div>
28 <table class="form-layout">
29 <tr class="crm-custom-field-form-block-label">
30 <td class="label">{$form.label.label}
31 {if $action == 2}
32 {include file='CRM/Core/I18n/Dialog.tpl' table='civicrm_custom_field' field='label' id=$id}
33 {/if}
34 </td>
35 <td class="html-adjust">{$form.label.html}</td>
36 </tr>
37 <tr class="crm-custom-field-form-block-data_type">
38 <td class="label">{$form.data_type.label}</td>
39 <td class="html-adjust">{$form.data_type.html}
40 {if $action neq 4 and $action neq 2}
41 <br /><span class="description">{ts}Select the type of data you want to collect and store for this contact. Then select from the available HTML input field types (choices are based on the type of data being collected).{/ts}</span>
42 {/if}
43 {if $action eq 2 and $changeFieldType}
44 <br />
45 <a class="action-item crm-hover-button" href='{crmURL p="civicrm/admin/custom/group/field/changetype" q="reset=1&id=`$id`"}'>
46 <i class="crm-i fa-wrench"></i>
47 {ts}Change Input Field Type{/ts}
48 </a>
49 <div class='clear'></div>
50 {/if}
51 </td>
52 </tr>
53 {if $form.in_selector}
54 <tr class='crm-custom-field-form-block-in_selector'>
55 <td class='label'>{$form.in_selector.label}</td>
56 <td class='html-adjust'>{$form.in_selector.html} {help id="id-in_selector"}</td>
57 </tr>
6a488035 58 {/if}
9edef7c7
CW
59 <tr class="crm-custom-field-form-block-text_length" id="textLength" {if !( $action eq 1 || $action eq 2 ) && ($form.data_type.value.0.0 != 0)}class="hiddenElement"{/if}>
60 <td class="label">{$form.text_length.label}</td>
61 <td class="html-adjust">{$form.text_length.html}</td>
62 </tr>
6a488035 63
9edef7c7
CW
64 <tr id='showoption' {if $action eq 1 or $action eq 2 }class="hiddenElement"{/if}>
65 <td colspan="2">
66 <table class="form-layout-compressed">
67 {* Conditionally show table for setting up selection options - for field types = radio, checkbox or select *}
68 {include file="CRM/Custom/Form/Optionfields.tpl"}
69 </table>
70 </td>
71 </tr>
72 <tr id='contact_reference_group'>
73 <td class="label">{$form.group_id.label}</td>
74 <td class="html-adjust">
75 {$form.group_id.html}
76 &nbsp;&nbsp;<span><a class="crm-hover-button toggle-contact-ref-mode" href="#Advance">{ts}Advanced Filter{/ts}</a></span>
77 {capture assign=searchPreferences}{crmURL p="civicrm/admin/setting/search" q="reset=1"}{/capture}
78 <div class="messages status no-popup"><i class="crm-i fa-exclamation-triangle"></i> {ts 1=$searchPreferences}If you are planning on using this field in front-end profile, event registration or contribution forms, you should 'Limit List to Group' or configure an 'Advanced Filter' (so that you do not unintentionally expose your entire set of contacts). Users must have either 'access contact reference fields' OR 'access CiviCRM' permission in order to use contact reference autocomplete fields. You can assign 'access contact reference fields' to the anonymous role if you want un-authenticated visitors to use this field. Use <a href='%1'>Search Preferences - Contact Reference Options</a> to control the fields included in the search results.{/ts}
79 </td>
80 </tr>
81 <tr id='field_advance_filter'>
82 <td class="label">{$form.filter.label}</td>
83 <td class="html-adjust">
84 {$form.filter.html}
85 &nbsp;&nbsp;<span><a class="crm-hover-button toggle-contact-ref-mode" href="#Group">{ts}Filter by Group{/ts}</a></span>
6a488035 86 <br />
a1252311 87 <span class="description">{ts}Filter contact search results for this field using Contact get API parameters. EXAMPLE: To list Students in group 3:{/ts} "action=get&group=3&contact_sub_type=Student" {docURL page="Using the API" resource="wiki"}</span>
9edef7c7
CW
88 </td>
89 </tr>
90 <tr class="crm-custom-field-form-block-options_per_line" id="optionsPerLine" {if $action neq 2 && ($form.data_type.value.0.0 >= 4 && $form.data_type.value.1.0 neq 'CheckBox' || $form.data_type.value.1.0 neq 'Radio' )}class="hiddenElement"{/if}>
91 <td class="label">{$form.options_per_line.label}</td>
92 <td class="html-adjust">{$form.options_per_line.html|crmAddClass:two}</td>
93 </tr>
94 <tr class="crm-custom-field-form-block-start_date_years" id="startDateRange" {if $action neq 2 && ($form.data_type.value.0.0 != 5)}class="hiddenElement"{/if}>
95 <td class="label">{$form.start_date_years.label}</td>
96 <td class="html-adjust">{$form.start_date_years.html} {ts}years prior to current date.{/ts}</td>
97 </tr>
98 <tr class="crm-custom-field-form-block-end_date_years" id="endDateRange" {if $action neq 2 && ($form.data_type.value.0.0 != 5)}class="hiddenElement"{/if}>
99 <td class="label">{$form.end_date_years.label}</td>
100 <td class="html-adjust">{$form.end_date_years.html} {ts}years after the current date.{/ts}</td>
101 </tr>
102 <tr class="crm-custom-field-form-block-date_format" id="includedDatePart" {if $action neq 2 && ($form.data_type.value.0.0 != 5)}class="hiddenElement"{/if}>
103 <td class="label">{$form.date_format.label}</td>
104 <td class="html-adjust">{$form.date_format.html}&nbsp;&nbsp;&nbsp;{$form.time_format.label}&nbsp;&nbsp;{$form.time_format.html}</td>
105 </tr>
106 <tr class="crm-custom-field-form-block-note_rows" id="noteRows" {if $action neq 2 && ($form.data_type.value.0.0 != 4)}class="hiddenElement"{/if}>
107 <td class="label">{$form.note_rows.label}</td>
108 <td class="html-adjust">{$form.note_rows.html}</td>
109 </tr>
110 <tr class="crm-custom-field-form-block-note_columns" id="noteColumns" {if $action neq 2 && ($form.data_type.value.0.0 != 4)}class="hiddenElement"{/if}>
111 <td class="label">{$form.note_columns.label}</td>
112 <td class="html-adjust">{$form.note_columns.html}</td>
113 </tr>
114 <tr class="crm-custom-field-form-block-note_length" id="noteLength" {if $action neq 2 && ($form.data_type.value.0.0 != 4)}class="hiddenElement"{/if}>
115 <td class="label">{$form.note_length.label}</td>
116 <td class="html-adjust">{$form.note_length.html} <span class="description">{ts}Leave blank for unlimited. This limit is not implemented by all browsers and rich text editors.{/ts}</span></td>
117 </tr>
118 <tr class="crm-custom-field-form-block-weight" >
119 <td class="label">{$form.weight.label}</td>
120 <td>{$form.weight.html|crmAddClass:two}
121 {if $action neq 4}
122 <span class="description">{ts}Weight controls the order in which fields are displayed in a group. Enter a positive or negative integer - lower numbers are displayed ahead of higher numbers.{/ts}</span>
123 {/if}
124 </td>
125 </tr>
126 <tr class="crm-custom-field-form-block-default_value" id="hideDefault" {if $action eq 2 && ($form.data_type.value.0.0 < 4 && $form.data_type.value.1.0 NEQ 'Text')}class="hiddenElement"{/if}>
127 <td title="hideDefaultValTxt" class="label">{$form.default_value.label}</td>
128 <td title="hideDefaultValDef" class="html-adjust">{$form.default_value.html}</td>
129 </tr>
130 <tr class="crm-custom-field-form-block-description" id="hideDesc" {if $action neq 4 && $action eq 2 && ($form.data_type.value.0.0 < 4 && $form.data_type.value.1.0 NEQ 'Text')}class="hiddenElement"{/if}>
131 <td title="hideDescTxt" class="label">&nbsp;</td>
132 <td title="hideDescDef" class="html-adjust"><span class="description">{ts}If you want to provide a default value for this field, enter it here. For date fields, format is YYYY-MM-DD.{/ts}</span></td>
133 </tr>
134 <tr class="crm-custom-field-form-block-help_pre">
135 <td class="label">{$form.help_pre.label} {if $action == 2}{include file='CRM/Core/I18n/Dialog.tpl' table='civicrm_custom_field' field='help_pre' id=$id}{/if}</td>
136 <td class="html-adjust">{$form.help_pre.html|crmAddClass:huge}</td>
137 </tr>
138 <tr class="crm-custom-field-form-block-help_post">
139 <td class="label">{$form.help_post.label} {if $action == 2}{include file='CRM/Core/I18n/Dialog.tpl' table='civicrm_custom_field' field='help_post' id=$id}{/if}</td>
140 <td class="html-adjust">{$form.help_post.html|crmAddClass:huge}
141 {if $action neq 4}
142 <span class="description">{ts}Explanatory text displayed on back-end forms. Pre help is displayed inline on the form (above the field). Post help is displayed in a pop-up - users click the help balloon to view help text.{/ts}</span>
143 {/if}
144 </td>
145 </tr>
146 <tr class="crm-custom-field-form-block-is_required">
147 <td class="label">{$form.is_required.label}</td>
148 <td class="html-adjust">{$form.is_required.html}
149 {if $action neq 4}
150 <br /><span class="description">{ts}Do not make custom fields required unless you want to force all users to enter a value anytime they add or edit this type of record. You can always make the field required when used in a specific Profile form.{/ts}</span>
151 {/if}
152 </td>
153 </tr>
154 <tr id ="searchable" class="crm-custom-field-form-block-is_searchable">
155 <td class="label">{$form.is_searchable.label}</td>
156 <td class="html-adjust">{$form.is_searchable.html}
157 {if $action neq 4}
158 <br /><span class="description">{ts}Can you search on this field in the Advanced and component search forms? Also determines whether you can include this field as a display column and / or filter in related detail reports.{/ts}</span>
159 {/if}
160 </td>
161 </tr>
162 <tr id="searchByRange" class="crm-custom-field-form-block-is_search_range">
6a488035 163 <td class="label">{$form.is_search_range.label}</td>
9edef7c7
CW
164 <td class="html-adjust">{$form.is_search_range.html}</td>
165 </tr>
166 <tr class="crm-custom-field-form-block-is_active">
167 <td class="label">{$form.is_active.label}</td>
168 <td class="html-adjust">{$form.is_active.html}</td>
169 </tr>
170 <tr class="crm-custom-field-form-block-is_view">
171 <td class="label">{$form.is_view.label}</td>
172 <td class="html-adjust">{$form.is_view.html}
173 <span class="description">{ts}Is this field set by PHP code (via a custom hook). This field will not be updated by CiviCRM.{/ts}</span>
174 </td>
175 </tr>
176 </table>
177 {if $action ne 4}
178 <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
179 {else}
180 <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
181 {/if}
182</div>
6a488035
TO
183{literal}
184<script type="text/javascript">
10ede6e5
CW
185 CRM.$(function($) {
186 var $form = $('form.{/literal}{$form.formClass}{literal}'),
9edef7c7
CW
187 dataTypes = {/literal}{$dataTypeKeys|@json_encode}{literal};
188
9edef7c7
CW
189 function showSearchRange() {
190 var htmlType = $("[name='data_type[1]']", $form).val(),
191 dataType = dataTypes[$("[name='data_type[0]']", $form).val()];
6a488035 192
0afd6ed2 193 if (dataType === 'Int' || dataType === 'Float' || dataType === 'Money' || dataType === 'Date') {
9edef7c7
CW
194 if ($('#is_searchable', $form).is(':checked')) {
195 $("#searchByRange", $form).show();
196 } else {
197 $("#searchByRange", $form).hide();
6a488035 198 }
9edef7c7
CW
199 } else {
200 $("#searchByRange", $form).hide();
201 }
6a488035
TO
202 }
203
9edef7c7
CW
204 function toggleContactRefFilter(e) {
205 var setSelected = $(this).attr('href');
206 if (!setSelected) {
207 setSelected = $('#filter_selected').val();
208 } else {
209 $('#filter_selected').val(setSelected.slice(1));
210 }
211 if (setSelected == '#Advance') {
212 $('#contact_reference_group').hide( );
213 $('#field_advance_filter').show( );
214 } else {
215 $('#field_advance_filter').hide( );
216 $('#contact_reference_group').show( );
217 }
218 e && e.preventDefault && e.preventDefault();
6a488035 219 }
9edef7c7
CW
220 $('.toggle-contact-ref-mode', $form).click(toggleContactRefFilter);
221
222 function customOptionHtmlType() {
223 var htmlType = $("[name='data_type[1]']", $form).val(),
224 dataTypeId = $("[name='data_type[0]']", $form).val(),
225 dataType = dataTypes[dataTypeId],
226 radioOption, checkBoxOption;
6a488035 227
9edef7c7
CW
228 if (!htmlType && !dataTypeId) {
229 return;
230 }
231
232 if (dataType === 'ContactReference') {
233 toggleContactRefFilter();
6a488035 234 } else {
9edef7c7 235 $('#field_advance_filter, #contact_reference_group', $form).hide();
6a488035 236 }
9edef7c7
CW
237
238 if (dataTypeId < 4) {
239 if (htmlType !== "Text") {
240 $("#showoption, #searchable", $form).show();
241 $("#hideDefault, #hideDesc, #searchByRange", $form).hide();
242 } else {
243 $("#showoption").hide();
244 $("#hideDefault, #hideDesc, #searchable", $form).show();
245 }
6a488035 246 } else {
9edef7c7
CW
247 if (dataType === 'File') {
248 $("#default_value", $form).val('');
249 $("#hideDefault, #searchable, #hideDesc", $form).hide();
250 } else if (dataType === 'ContactReference') {
251 $("#hideDefault").hide();
252 } else {
253 $("#hideDefault, #searchable, #hideDesc", $form).show();
254 }
255 $("#showoption").hide();
256 }
257
258 for (var i=1; i<=11; i++) {
259 radioOption = 'radio'+i;
260 checkBoxOption = 'checkbox'+i;
261 if (dataTypeId < 4) {
262 if (htmlType != "Text") {
263 if (htmlType == "CheckBox" || htmlType == "Multi-Select") {
264 $("#"+checkBoxOption, $form).show();
265 $("#"+radioOption, $form).hide();
266 } else {
267 $("#"+radioOption, $form).show();
268 $("#"+checkBoxOption, $form).hide();
269 }
270 }
271 }
6a488035 272 }
9edef7c7
CW
273
274 $("#optionsPerLine", $form).toggle((htmlType == "CheckBox" || htmlType == "Radio") && dataType !== 'Boolean');
275
276 $("#startDateRange, #endDateRange, #includedDatePart", $form).toggle(dataType === 'Date');
277
278 $("#textLength", $form).toggle(dataType === 'String');
279
280 $("#noteColumns, #noteRows, #noteLength", $form).toggle(dataType === 'Memo');
6a488035 281 }
9edef7c7
CW
282
283 $('[name^="data_type"]', $form).change(customOptionHtmlType);
284 customOptionHtmlType();
0afd6ed2
CW
285 $('#is_searchable, [name^="data_type"]', $form).change(showSearchRange);
286 showSearchRange();
9edef7c7 287 });
6a488035
TO
288</script>
289{/literal}
290{* Give link to view/edit choice options if in edit mode and html_type is one of the multiple choice types *}
291{if $action eq 2 AND ($form.data_type.value.1.0 eq 'CheckBox' OR ($form.data_type.value.1.0 eq 'Radio' AND $form.data_type.value.0.0 neq 6) OR $form.data_type.value.1.0 eq 'Select' OR ($form.data_type.value.1.0 eq 'Multi-Select' AND $dontShowLink neq 1 ) ) }
9edef7c7
CW
292 <div class="action-link">
293 {crmButton p="civicrm/admin/custom/group/field/option" q="reset=1&action=browse&fid=`$id`&gid=`$gid`" icon="pencil"}{ts}View / Edit Multiple Choice Options{/ts}{/crmButton}
294 </div>
6a488035 295{/if}