[CONTRIB] Yes/no element now prints tick or cross only when there is data

chozma

Member
My first code contribution to you so I hope I have done this right! I haven't tackled GitHub yet, on my list of things to learn once I launch on my current project.

Code contribution details
The Yes/No element in List view displays a tick or a cross for 1 and 0 respectively. However at the moment it also displays a cross if there is no data/no record.

I don't find that particularly useful especially as I have lots of lists where I have joined data so I get lots of random crosses everywhere.

Here is a before and after of what I am talking about:

BEFORE - rows 2, 5 and 6 don't have associated mob records, so there is no data. Really these should be blank.
With crosses where there is no data.PNG

AFTER - blanks where they should be blanks in rows 2, 5 and 6.
Blank when there is no data.PNG
The code was incredibly simple to change, only two lines really. The forum won't let me upload a PHP file to attach so its here at the bottom of this post:

I hope this is useful and that others somewhere might find it helpful too. Please let me know, thanks ;)

fabrik_element_yesno_list.php
PHP:
<?php
/**
* Layout: Yes/No field list view
*
* @package    Joomla
* @subpackage  Fabrik
* @copyright  Copyright (C) 2005-2014 fabrikar.com - All rights reserved.
* @license    GNU/GPL http://www.gnu.org/copyleft/gpl.html
* @since      3.2
*/
 
// No direct access
defined('_JEXEC') or die('Restricted access');
$d = $displayData;
$data = $d->value;
$tmpl = $d->tmpl;
$j3 = FabrikWorker::j3();
 
if ($data == '1') :
    $icon = $j3 ? 'checkmark.png' : '1.png';
    $opts = array('alt' => FText::_('JYES'));
   
    echo FabrikHelperHTML::image($icon, 'list', $tmpl, $opts);
elseif($data == '0') :
    $icon = $j3 ? 'remove.png' : '0.png';
   
    echo FabrikHelperHTML::image($icon, 'list', $tmpl, array('alt' => FText::_('JNO')));
else :
    //display nothing, there's no data
endif;
 
Rather than modifying the main code, this is a good example of what those layouts are for. They are basically mini templates, which can be overrides with custom ones.

In this case, although you may prefer a blank for 'no data', other people may not. And we are always leary about changing existing behavior. So there's two choices. Either we add an option for the element to control this behavior, or you simply override the layout, so it behaves how you want it to.

Check the wiki, there's a page that explains how to override the layout, which is to put your copy in a specific location.

Hugh
 
Great, thanks for the help Hugh. It didn't occur to me to override the layout for that which of course would be much better!
 
We are in need of some funding.
More details.

Thank you.

Staff online

Members online

Back
Top