Update CustomField form with 'serialize' option
[civicrm-core.git] / templates / CRM / Custom / Form / Field.tpl
1 {*
2 +--------------------------------------------------------------------+
3 | Copyright CiviCRM LLC. All rights reserved. |
4 | |
5 | This work is published under the GNU AGPLv3 license with some |
6 | permitted exceptions and without any warranty. For full license |
7 | and copyright information, see https://civicrm.org/licensing |
8 +--------------------------------------------------------------------+
9 *}
10 <div class="crm-block crm-form-block crm-custom-field-form-block">
11 <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="top"}</div>
12 <table class="form-layout">
13 <tr class="crm-custom-field-form-block-label">
14 <td class="label">{$form.label.label}
15 {if $action == 2}
16 {include file='CRM/Core/I18n/Dialog.tpl' table='civicrm_custom_field' field='label' id=$id}
17 {/if}
18 </td>
19 <td class="html-adjust">{$form.label.html}</td>
20 </tr>
21 <tr class="crm-custom-field-form-block-data_type">
22 <td class="label">{$form.data_type.label}</td>
23 <td class="html-adjust">{$form.data_type.html}
24 {if $action neq 4 and $action neq 2}
25 <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>
26 {/if}
27 {if $action eq 2 and $changeFieldType}
28 <br />
29 <a class="action-item crm-hover-button" href='{crmURL p="civicrm/admin/custom/group/field/changetype" q="reset=1&id=`$id`"}'>
30 <i class="crm-i fa-wrench"></i>
31 {ts}Change Input Field Type{/ts}
32 </a>
33 <div class='clear'></div>
34 {/if}
35 </td>
36 </tr>
37 <tr class="crm-custom-field-form-block-serialize">
38 <td class="label">{$form.serialize.label}</td>
39 <td class="html-adjust">{$form.serialize.html}</td>
40 </tr>
41 {if $form.in_selector}
42 <tr class='crm-custom-field-form-block-in_selector'>
43 <td class='label'>{$form.in_selector.label}</td>
44 <td class='html-adjust'>{$form.in_selector.html} {help id="id-in_selector"}</td>
45 </tr>
46 {/if}
47 <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}>
48 <td class="label">{$form.text_length.label}</td>
49 <td class="html-adjust">{$form.text_length.html}</td>
50 </tr>
51
52 <tr id='showoption' {if $action eq 1 or $action eq 2 }class="hiddenElement"{/if}>
53 <td colspan="2">
54 <table class="form-layout-compressed">
55 {* Conditionally show table for setting up selection options - for field types = radio, checkbox or select *}
56 {include file="CRM/Custom/Form/Optionfields.tpl"}
57 </table>
58 </td>
59 </tr>
60 <tr id='contact_reference_group'>
61 <td class="label">{$form.group_id.label}</td>
62 <td class="html-adjust">
63 {$form.group_id.html}
64 &nbsp;&nbsp;<span><a class="crm-hover-button toggle-contact-ref-mode" href="#Advance">{ts}Advanced Filter{/ts}</a></span>
65 {capture assign=searchPreferences}{crmURL p="civicrm/admin/setting/search" q="reset=1"}{/capture}
66 <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}
67 </td>
68 </tr>
69 <tr id='field_advance_filter'>
70 <td class="label">{$form.filter.label}</td>
71 <td class="html-adjust">
72 {$form.filter.html}
73 &nbsp;&nbsp;<span><a class="crm-hover-button toggle-contact-ref-mode" href="#Group">{ts}Filter by Group{/ts}</a></span>
74 <br />
75 <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>
76 </td>
77 </tr>
78 <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}>
79 <td class="label">{$form.options_per_line.label}</td>
80 <td class="html-adjust">{$form.options_per_line.html|crmAddClass:two}</td>
81 </tr>
82 <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}>
83 <td class="label">{$form.start_date_years.label}</td>
84 <td class="html-adjust">{$form.start_date_years.html} {ts}years prior to current date.{/ts}</td>
85 </tr>
86 <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}>
87 <td class="label">{$form.end_date_years.label}</td>
88 <td class="html-adjust">{$form.end_date_years.html} {ts}years after the current date.{/ts}</td>
89 </tr>
90 <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}>
91 <td class="label">{$form.date_format.label}</td>
92 <td class="html-adjust">{$form.date_format.html}&nbsp;&nbsp;&nbsp;{$form.time_format.label}&nbsp;&nbsp;{$form.time_format.html}</td>
93 </tr>
94 <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}>
95 <td class="label">{$form.note_rows.label}</td>
96 <td class="html-adjust">{$form.note_rows.html}</td>
97 </tr>
98 <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}>
99 <td class="label">{$form.note_columns.label}</td>
100 <td class="html-adjust">{$form.note_columns.html}</td>
101 </tr>
102 <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}>
103 <td class="label">{$form.note_length.label}</td>
104 <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>
105 </tr>
106 <tr class="crm-custom-field-form-block-weight" >
107 <td class="label">{$form.weight.label}</td>
108 <td>{$form.weight.html|crmAddClass:two}
109 {if $action neq 4}
110 <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>
111 {/if}
112 </td>
113 </tr>
114 <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}>
115 <td title="hideDefaultValTxt" class="label">{$form.default_value.label}</td>
116 <td title="hideDefaultValDef" class="html-adjust">{$form.default_value.html}</td>
117 </tr>
118 <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}>
119 <td title="hideDescTxt" class="label">&nbsp;</td>
120 <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>
121 </tr>
122 <tr class="crm-custom-field-form-block-help_pre">
123 <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>
124 <td class="html-adjust">{$form.help_pre.html|crmAddClass:huge}</td>
125 </tr>
126 <tr class="crm-custom-field-form-block-help_post">
127 <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>
128 <td class="html-adjust">{$form.help_post.html|crmAddClass:huge}
129 {if $action neq 4}
130 <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>
131 {/if}
132 </td>
133 </tr>
134 <tr class="crm-custom-field-form-block-is_required">
135 <td class="label">{$form.is_required.label}</td>
136 <td class="html-adjust">{$form.is_required.html}
137 {if $action neq 4}
138 <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>
139 {/if}
140 </td>
141 </tr>
142 <tr id ="searchable" class="crm-custom-field-form-block-is_searchable">
143 <td class="label">{$form.is_searchable.label}</td>
144 <td class="html-adjust">{$form.is_searchable.html}
145 {if $action neq 4}
146 <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>
147 {/if}
148 </td>
149 </tr>
150 <tr id="searchByRange" class="crm-custom-field-form-block-is_search_range">
151 <td class="label">{$form.is_search_range.label}</td>
152 <td class="html-adjust">{$form.is_search_range.html}</td>
153 </tr>
154 <tr class="crm-custom-field-form-block-is_active">
155 <td class="label">{$form.is_active.label}</td>
156 <td class="html-adjust">{$form.is_active.html}</td>
157 </tr>
158 <tr class="crm-custom-field-form-block-is_view">
159 <td class="label">{$form.is_view.label}</td>
160 <td class="html-adjust">{$form.is_view.html}
161 <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>
162 </td>
163 </tr>
164 </table>
165 {if $action ne 4}
166 <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
167 {else}
168 <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
169 {/if}
170 </div>
171 {literal}
172 <script type="text/javascript">
173 CRM.$(function($) {
174 var $form = $('form.{/literal}{$form.formClass}{literal}'),
175 dataTypes = {/literal}{$dataTypeKeys|@json_encode}{literal};
176
177 function showSearchRange() {
178 var htmlType = $("[name='data_type[1]']", $form).val(),
179 dataType = dataTypes[$("[name='data_type[0]']", $form).val()];
180
181 if (dataType === 'Int' || dataType === 'Float' || dataType === 'Money' || dataType === 'Date') {
182 if ($('#is_searchable', $form).is(':checked')) {
183 $("#searchByRange", $form).show();
184 } else {
185 $("#searchByRange", $form).hide();
186 }
187 } else {
188 $("#searchByRange", $form).hide();
189 }
190 }
191
192 function toggleContactRefFilter(e) {
193 var setSelected = $(this).attr('href');
194 if (!setSelected) {
195 setSelected = $('#filter_selected').val();
196 } else {
197 $('#filter_selected').val(setSelected.slice(1));
198 }
199 if (setSelected == '#Advance') {
200 $('#contact_reference_group').hide( );
201 $('#field_advance_filter').show( );
202 } else {
203 $('#field_advance_filter').hide( );
204 $('#contact_reference_group').show( );
205 }
206 e && e.preventDefault && e.preventDefault();
207 }
208 $('.toggle-contact-ref-mode', $form).click(toggleContactRefFilter);
209
210 function customOptionHtmlType() {
211 var htmlType = $("[name='data_type[1]']", $form).val(),
212 dataTypeId = $("[name='data_type[0]']", $form).val(),
213 dataType = dataTypes[dataTypeId],
214 radioOption, checkBoxOption;
215
216 if (!htmlType && !dataTypeId) {
217 return;
218 }
219
220 if (dataType === 'ContactReference') {
221 toggleContactRefFilter();
222 } else {
223 $('#field_advance_filter, #contact_reference_group', $form).hide();
224 }
225
226 if (dataTypeId < 4) {
227 if (htmlType !== "Text") {
228 $("#showoption, #searchable", $form).show();
229 $("#hideDefault, #hideDesc, #searchByRange", $form).hide();
230 } else {
231 $("#showoption").hide();
232 $("#hideDefault, #hideDesc, #searchable", $form).show();
233 }
234 } else {
235 if (dataType === 'File') {
236 $("#default_value", $form).val('');
237 $("#hideDefault, #searchable, #hideDesc", $form).hide();
238 } else if (dataType === 'ContactReference') {
239 $("#hideDefault").hide();
240 } else {
241 $("#hideDefault, #searchable, #hideDesc", $form).show();
242 }
243 $("#showoption").hide();
244 }
245
246 for (var i=1; i<=11; i++) {
247 radioOption = 'radio'+i;
248 checkBoxOption = 'checkbox'+i;
249 if (dataTypeId < 4) {
250 if (htmlType != "Text") {
251 if (htmlType == "CheckBox" || htmlType == "Multi-Select") {
252 $("#"+checkBoxOption, $form).show();
253 $("#"+radioOption, $form).hide();
254 } else {
255 $("#"+radioOption, $form).show();
256 $("#"+checkBoxOption, $form).hide();
257 }
258 }
259 }
260 }
261
262 $("#optionsPerLine", $form).toggle((htmlType == "CheckBox" || htmlType == "Radio") && dataType !== 'Boolean');
263
264 $("#startDateRange, #endDateRange, #includedDatePart", $form).toggle(dataType === 'Date');
265
266 $("#textLength", $form).toggle(dataType === 'String');
267
268 $("#noteColumns, #noteRows, #noteLength", $form).toggle(dataType === 'Memo');
269
270 $(".crm-custom-field-form-block-serialize", $form).toggle(htmlType === 'Select' || htmlType === 'Country' || htmlType === 'StateProvince');
271 }
272
273 $('[name^="data_type"]', $form).change(customOptionHtmlType);
274 customOptionHtmlType();
275 $('#is_searchable, [name^="data_type"]', $form).change(showSearchRange);
276 showSearchRange();
277 });
278 </script>
279 {/literal}
280 {* Give link to view/edit choice options if in edit mode and html_type is one of the multiple choice types *}
281 {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 ) ) }
282 <div class="action-link">
283 {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}
284 </div>
285 {/if}