Hi all
We are building a custom presenter (actually editing the copy to clipboard presenter) we need to be able to ‘omit if blank’ but don’t know how to add this into our code. can anyone help?
Thanks
Kev
Hi all
We are building a custom presenter (actually editing the copy to clipboard presenter) we need to be able to ‘omit if blank’ but don’t know how to add this into our code. can anyone help?
Thanks
Kev
Hi Kevin,
The simplest way to achieve this would be to add a setting in the main.js.
get_settings: function() {
return {
omit_if_blank : {
csid:'omit_if_blank',
main_label:"Omit if Blank",
base_format:"boolean",
preset: 0
},
Add the setting to the get_template_data return:
return {
get_template_data: function() {
return {
...
omit_if_blank : (presenter.get_setting('omit_if_blank') == 1 ? 1 : 0)
Next, you will want to add some logic either to your main.js or frontend.js to set a flag to omit the html under the condition that omit_if_blank is True and your value is null or empty.
hide = omit_if_blank && !value;
Then add a v-if attribute to any html tag in main.htm. This will show the contents of the div for as long as show is true.
<div v-if="!hide">
Everything here is hidden when hide is false.
</div>
Hope this helps.
Hi, thanks Adam. Your suggestion is for hiding elements within the presenter, but the standard ‘omit if blank’ setting that we’re refering to is a ‘fragment setting’ which should hide the whole field (i.e. including the field’s label) if there’s no data, and so it’s outside of the scope of the presenter’s html.
Hope that makes sense,
James
Thanks James,
You raise a very valid point, this will only make the field disappear and not the wrapper.
Let me raise this with core and I’ll get back to you.
Hi James,
Have spoken with Core and have been asked to add it as an idea, as these are up for review imminently.
Please add your support and a comment.
https://ideas.netcall.com/i/ideas/p/feature/vote/idea/view?context_record_id=3887
Many Thanks
Morning Kevin,
In the rush up to Christmas, it appears I overlooked a vital detail here.
It appears the ‘omit if blank’ option will only appear for presenters that have their purpose set to ‘display’.
If you think about it, that is extremely valid, as editable fields will often be intentionally blank.
You weren’t clear on the purpose of your modified clipboard helper presenter, but the purpose set for that presenter is ‘modify’ and not ‘display’.
Given your requirement for ‘omit if blank’ I can only presume you have modified the presenter for a display only purpose and as such you need only alter the purpose on the basic tab of the presenter to enable the ‘omit of blank’ option in page builder.
Hope this helps.