I would like to convert all the form fields labels of the contribution pages and events pages into placeholder. Is it possible to do? If yes, how please ? Thanks
5
-
Can you provide an example of the end result you want to achieve? – Aidan♦ Mar 13 '20 at 8:50
-
@Aidan say for names, address, any custom fields that are usually available by profile, for those ones remove labels and show a placeholder of the same name as labels. – Tapash Mar 13 '20 at 8:52
-
Still not sure I understand what you want to do, but does Word Replacement or even translation help? – Aidan♦ Mar 13 '20 at 9:01
-
@Aidan I have added screenshot – Tapash Mar 13 '20 at 12:49
-
Ah - I get it now! A picture is worth a 1000 words etc ... – Aidan♦ Mar 13 '20 at 14:09
Add a comment
|
You write a small jQuery script and include it on your forms
<script type="text/javascript">
CRM.$(function($) {
let label, labelDiv, value;
$('input').each(function() {
value = $(this).val();
labelDiv = $(this).closest('.crm-section').find('.label');
$(labelDiv).hide();
label = $(labelDiv).text();
label = label.replace(/\s\s+/g, ' ');
$(this).attr("placeholder", label);
});
});
</script>
There are various ways to include jquery in your forms
- Implement hook(buildform or preprocess or pagerun) via extension/plugin/module to add js using add resource method
- Override tpl file using extra.tpl method to include jquery
-
-
-
-
-
If you trying to override the template by custom templates or extra.tpl than make sure your extension or module or plugin dont have this file already in their folder than either yours or module will be invoked based on how ext or module is invoked – Pradeep Nayak Mar 13 '20 at 14:53