Question about buttons

joit

Active Member
Hi,

it would be great if the "Apply" button would only be visible for form (edit) and the "Save" button would only be visible for form (add). Is there a way to get this behavior?

Thanks
Hannes
 
You could do that by customizing a template. In default_actions.php ...

Code:
        <?php if ( $form->submitButton || $form->applyButton || $form->copyButton ): ?>
            <div class="span4">
                <div class="btn-group">
                    <?php
                    echo $form->submitButton . ' ';
                    echo $form->applyButton . ' ';
                    echo $form->copyButton;
                    ?>
                </div>
            </div>
        <?php endif; ?>

... you could use $this->getModel()->isNewRecord(), like ...

Code:
        <?php if ( $form->submitButton || $form->applyButton || $form->copyButton ): ?>
            <div class="span4">
                <div class="btn-group">
                    <?php
                    if ($this->getModel()->isNewRecord()) {
                       echo $form->submitButton . ' ';
                    }
                    else {
                       echo $form->applyButton . ' ';
                    }
                    echo $form->copyButton;
                    ?>
                </div>
            </div>
        <?php endif; ?>

... and enable both buttons in the form settings.

-- hugh
 
I played with it and it works really nice! But I have 2 questions about it.
Will it be overridden with the next GH update?
What I actually wanted to have, is 2 different labels and icons but the same behaviour for add and edit form. So the add button could have the label "Add" and the edit button could have the name "Edit". Now, when you click the apply button, it doesn't close the form. Is there a way to do this?
 
Will it be overridden with the next GH update?
No, if you have created a custom template (i.e. a copy of bootstrap). Yes, if you've modified the bootstrap template directly
 
Well, I modified the file in this path:
components/com_fabrik/views/form/tmpl/bootstrap
How would I copy that?
 
To create a custom template copy the complete bootstrap folder (to e.g. mybootstrap) and do the modifications there (and use mybootstrap in your form settings).
 
I like that!
Now I'd like to get back to this
What I actually wanted to have, is 2 different labels and icons but the same behaviour for add and edit form. So the add button could have the label "Add" and the edit button could have the name "Edit". Now, when you click the apply button, it doesn't close the form. Is there a way to do this?

So actually 2 save buttons would be great.
 
Now, when you click the apply button, it doesn't close the form. Is there a way to do this?

Well, that's the whole point of the "Apply" button. It saves your form, and re-opens it (ignoring any redirects). That's pretty much the standard in UIs ... "Save" will save and close whatever you are working on, "Apply" saves but doesn't close.

So what I think you are really trying to achieve is simply change the label on the save button, so for new forms it says "Save" and when editing it says "Edit"?

-- hugh
 
So what I think you are really trying to achieve is simply change the label on the save button, so for new forms it says "Save" and when editing it says "Edit"?

How could I do this?
It would be great to have different icons for add and edit, too
 
OK, I think the best way to do that would be with a layout override. All of the regular buttons in forms are rendered using ...

./components/com_fabrik/layouts/fabrik-button.php

So you can copy that to ...
./templates/<your site template/html/layouts/com_fabrik/fabrik-button.php

You'll need to pick up this change in github:

https://github.com/Fabrik/fabrik/commit/37f8027089c6fbaefd760912811f49bb940b5592

... which adds the $formModel to the layout data. You'll need that to figure out which form is being rendered (remembering that this layout gets called from lots of places). Then modify the layout to do something like this ...

Code:
defined('JPATH_BASE') or die;

$d          = $displayData;
$attributes = isset($d->attributes) ? $d->attributes : '';
$type       = isset($d->type) ? 'type="' . $d->type . '"' : 'type="button"';
$tag        = isset($d->tag) ? $d->tag : 'button'; // button or a
$name       = isset($d->name) ? 'name="' . $d->name . '"' : '';
$id = isset($d->id) ? 'id="' . $d->id .'"' : '';

// if form ID 123 and this is the Submit button, and we are editing a row, change the label to "Edit"
if ($d->formModel->getId() = '123' && $d->type == 'Submit' && !$d->formModel->isNewRecord()) {
   $d->label = "Edit";
}
?>

<<?php echo $tag; ?> <?php echo $type; ?> class="btn <?php echo $d->class; ?>" <?php echo $attributes; ?>
    <?php echo $name; ?> <?php echo $id; ?>>
    <?php echo $d->label; ?>
</<?php echo $tag; ?>>

So add that condition with the comment on it that changes $d->label.

Any icons you use are included in the label at that point, so you can examine the markup for your Apply button, and insert the appropriate icon markup in the label with the "Edit" word.

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top