conditionally hide a button in listview, how to?

mirceat

Member
Hello,

I've added the php plugin in list view in order to trigger an action and need to show this button only if the value for another element is set to 0. I think this might be done by using javascript, but i have no idea how to retrieve the element value in listview and i couldn't find an example in the forum.

Thank you
 
This is one of the code i using for hide button with some condition. Use at element JavaScript. Action = Onload

PHP:
var credit = form_2.formElements.get('bpv___current_balance').getValue().toInt();
var fee = form_2.formElements.get('bpv___application_fee').getValue().toInt();
 
if (credit < fee) {
    alert('Not Enough Credit!. Please reload your credit before submit new visa application. Submit button will be disable until your have enough credit.');
    document.getElement('.fabrikActions').hide();
}
if (credit >= fee) {
    document.getElement('.fabrikActions').show();
}
 
Hello myfatebiz,

Just to be sure that i understand: this code will hide the button in list view or in form view? I need to hide the button in listview, in form the element is not accesible to anybody (it's a yes/no element).
 
No, i'm trying to hide a php plugin button in listing, based on the following condition :

if (tablename___payment == 1)
show the php plugin button in listing
else
hide the php plugin button in listing

the php plugin button code will update an yes/no element tablename___cancel_order and send a notification to the Finance team.

In words, the users should be able to cancel the order only if the payment wasn't made. They can't edit the form, instead they should click on a button in listing to cancel the order.
 
In your yesno element's list settings you can enable "Use as row class" which will add a class your-yn-element0 resp. your-yn-element1 to the tr tag-
Then add custom CSS to hide the php button.

But be aware that any CSS (or JS) is no security means, any user who knows to can modify it.
So you have to validate in your php plugin, too.
 
Use the code below inside default_row.php. The ".php-0" is list php plugin number one. If php plugin number 2 use ".php-1". This class can see through inspect element.

PHP:
<?php
 
$payment = $this->_row->data->tablename___payment_raw;
 
?>
 
<?php if ($payment == 1){ ?>
<style type="text/css">.php-0 {
display:block !important;
}</style>
<?php } else { ?>
<style type="text/css">.php-0 {
display:none !important;
}</style>
<?php } ?>
 
Thank you,

troester: i don't understand how can i add the condition in the css file..can you give me an example, please?

myfatebiz: where should i put the code in page? inside the foreach statement or below it? I tried to run the code inside and outside the foreach, but it will show/hide the button for all rows, not just for the ones who meet the condition.
 
Your row will be
<tr class="yourelementname0" if element is 0
<tr class="yourelementname1" otherwise
so you can add something like
#listform_$c tr.yourelementname0 li a.xxx {
display: none;
}
with xxx is the class of your plugin (php-0 in the example of myfatebiz)
 
Example like as below on your default_row.php

PHP:
<?php
/**
* Fabrik List Template: Default Row
*
* @package    Joomla
* @subpackage  Fabrik
* @copyright  Copyright (C) 2005 Fabrik. All rights reserved.
* @license    http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
*/
 
// No direct access
defined('_JEXEC') or die;
?>
 
<?php
 
$payment = $this->_row->data->tablename___payment_raw;
 
?>
 
<?php if ($payment == 1){ ?>
<style type="text/css">.php-0 {
display:block !important;
}</style>
<?php } else { ?>
<style type="text/css">.php-0 {
display:none !important;
}</style>
<?php } ?>
 
<tr id="<?php echo $this->_row->id;?>" class="<?php echo $this->_row->class;?>">
    <?php foreach ($this->headings as $heading => $label) {
        $style = empty($this->cellClass[$heading]['style']) ? '' : 'style="'.$this->cellClass[$heading]['style'].'"';
        ?>
        <td class="<?php echo $this->cellClass[$heading]['class']?>" <?php echo $style?>>
            <?php echo @$this->_row->data->$heading;?>
        </td>
    <?php }?>
</tr>
 
Ignore my code above. That very lazy one. Here use the simple one without headache.

default_row.php

PHP:
<?php
/**
* Fabrik List Template: Default Row
*
* @package    Joomla
* @subpackage  Fabrik
* @copyright  Copyright (C) 2005 Fabrik. All rights reserved.
* @license    http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
*/
 
// No direct access
defined('_JEXEC') or die;
?>
 
<?php
 
$payment = $this->_row->data->tablename___payment_raw;
 
?>
 
<!-- Condition 1 -->
<?php IF ($payment == 1) { ?>
<tr id="<?php echo $this->_row->id;?>" class="<?php echo $this->_row->class;?> condition-1">
    <?php foreach ($this->headings as $heading => $label) {
        $style = empty($this->cellClass[$heading]['style']) ? '' : 'style="'.$this->cellClass[$heading]['style'].'"';
        ?>
        <td class="<?php echo $this->cellClass[$heading]['class']?>" <?php echo $style?>>
            <?php echo @$this->_row->data->$heading;?>
        </td>
    <?php }} ?>
</tr>
<!-- Condition 2 -->
<?php IF ($payment != 1) { ?>
<tr id="<?php echo $this->_row->id;?>" class="<?php echo $this->_row->class;?> condition-2">
    <?php foreach ($this->headings as $heading => $label) {
        $style = empty($this->cellClass[$heading]['style']) ? '' : 'style="'.$this->cellClass[$heading]['style'].'"';
        ?>
        <td class="<?php echo $this->cellClass[$heading]['class']?>" <?php echo $style?>>
            <?php echo @$this->_row->data->$heading;?>
        </td>
    <?php }} ?>
</tr>

put the code below inside custom_css.php

PHP:
.condition-1 > .fabrik_actions > .fabrik_action > li > .php-0 {
    display: block !important;
}
 
.condition-2 > .fabrik_actions > .fabrik_action > li > .php-0 {
    display: none !important;
}
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top