Silverstripe display logic for Front-end/Bootstrap forms - forms

Silverstripe Display Logic works perfectly on forms in the CMS but I cannot get it to work on forms in the front end, specifically Bootstrap forms.
It will hide the element but won't display it when logic is applied.
//If the wetsuit dropdown is equal to custom then show the fins numerical field.
DisplayLogicWrapper::create(NumericField::create("Fins","Fins"))->displayIf("Wetsuit")->isEqualTo('Custom')->end(),
I see it just needs display to change from none to block.
Is there a way to do this so that it will keep the state on page reload as well? The drop down value will be saved as a DB entry.
EDIT: This works in the CMS but doesn't work in the front end - Custom is part of the enum values.
DropdownField::create("Wetsuit","Wetsuit")
->setSource(singleton('DiveEquipment')->dbObject('Wetsuit')->enumValues())
->setEmptyString('Select one'),
NumericField::create('Fins','Fins')
->displayIf('Wetsuit')
->isEqualTo('Custom')
->end(),
EDIT2: Working with SilversTripe 3.5, Bootstrap Forms 1.20 and Display Logic 1.0.8
1.0.8 is very outdated though.

I don't think you need the DisplayLogicWrapper for most fields… It's meant for fields like UploadField.
Have you tried this?
NumericField::create('Fins','Fins')
->displayIf('Wetsuit')
->isEqualTo('Custom')
->end(),

Not the issue here, but it's worth noting that a bug exists in Display Logic 1.3 and lower where the custom templates exist in /templates/ not /templates/forms/, causing precedence issues.
If you're experiencing problems with a FieldGroup not rendering the correct template or whatnot. Upgrading to Display Logic 1.4 will resolve this.

You'll need to include jQuery and jQuery Entwine for this to work on the frontend. This is untested but should resolve your issue.
class Page_Controller extends ContentController {
public function init() {
parent::init();
Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js');
Requirements::javascript(THIRDPARTY_DIR . '/jquery-entwine/dist/jquery.entwine-dist.js');
}
}

Related

Filename not shown in Symfony 5.2 in form

I am just learning Symfony and maybe I am doing something wrong.
I created a simple form with the possibilty to upload a file. After choosing the file the filename doesn't show up in the form.
Screen 1 - Choose picture
Screen 2 - Filename isn't shown
The picturename is correctly saved to the database, so it must be there :)
I used ->add('picture', FileType::class, ['required' => false])
Can someone push me in the right direction. I am trying to figure this out for the last 2 hours.
There is a "bug" with that type of field in Symfony when using the Bootstrap form theme.
If you are using Symfony's Boostrap form theme
# config/packages/twig.yaml
twig:
default_path: '%kernel.project_dir%/templates'
form_themes:
- 'bootstrap_4_horizontal_layout.html.twig'
I would recommend adding some Javascript to fix this issue.
$('.custom-file-input').on('change', function(event) {
let inputFile = event.currentTarget;
$(inputFile).parent().find('.custom-file-label').html(inputFile.files[0].name);
});
Note that I'm using ES6 syntax here, for better compatibility with old browsers, you might want to use ES5 if you are not using a transpiler. Also, I using the custom-file-label class since I'm using Symfony's Bootstrap 4 form theme, you might want to adjust if you are using another theme.
..files[0].name is used since your FileType could accept multiple files.

TYPO3 7.6 Backend module table DataTable not working

I've been searching for quite a while but neither solution worked.
I have created a backend module which shall display orders in a table. I achieved creating a table containing the wanted information BUT I need some more functionality and I thought there would be an easy way.
The table should be sortable, filterable and searchable - functions that TYPO3 uses for displaying datasets in the backend already.
I have tried to make use of the DataTables which are already included by the core of TYPO3 and should be easily accessible according to the following links:
https://forum.typo3.org/index.php/t/210780/
https://typo3.com/blog/how-to-use-javascript-in-typo3s-backend/
TYPO3 backend modul DataTable is no function
I added a js-file according to the answer from Philipp Wrann in the first link:
/Resources/Public/JavaScript/OrderingTables.js:
define('TYPO3/CMS/GiPdShop', ['jquery', 'datatables'], function($) {
var OrderingTables = {};
// Initialize dataTables
OrderingTables.initializeDataTables = function() {
$('#orders-table').DataTable();
};
$(document).ready(function() {
// Initialize the view
OrderingTables.initializeDataTables();
});
});
As there are no errors and the file is included if I check in the dev-tools I believe this is not a bad approach. To use the file I added the following to the <f:be.container> in the template:
includeRequireJsModules="{0: 'TYPO3/CMS/GiPdShop/OrderingTables'}"
Yet it doesn't create a DataTable, no added classes to the rows or cells of the table and thus I assume that there is some kind of error, maybe a missing configuration, maybe another option I missed out somehow.
The only other solutions I found so far seem rather complicated and I would love to keep it as simple as possible (I am not a professional in TYPO3 (yet) and the module should already be functional).
Can someone see a mistake I haven't found? Is it even possible to add the wanted functionality in such an easy way?
Any help would be highly appreciated.
It's really a stupid little thing I was missing.
The path 'TYPO3/CMS/GiPdShop' in the definition was missing the module.
So the correct path would be 'TYPO3/CMS/GiPdShop/OrderingTables', the same I have added in the template.
Really stupid but maybe this helps someone someday who gets stuck as well...
#PaulBeck thanks again!

How to make a custom ListView page in SuiteCRM

I need to make a page in SuiteCRM (v7.9 -- based loosely on Sugar 6.5 CE) that has a list of objects (of a custom module), with checkboxes in front of each one. So far, so good: that's a standard ListView.
The catch is that only some records should be in the list (filtering on whether there is an associated row in a related custom module/object).
This page needs to be distinct from the "regular" list for this module, which should indeed list all records.
It seems to me it makes sense to use a custom "action" to access this page view, and I can get my custom action code to fire with the right URL.
But I don't see how to hook in the filtering. At first, it looked like the process_record logic hook might be helpful here, but it just gives the bean for every record to be displayed. Unless there's a flag "display this record" that I'm not seeing, that's not so helpful.
Ideally, of course, I'd like to be able to inject a different WHERE clause in my custom controller action before calling
parent::action_listview();
to display the page, but I'm not seeing doc to indicate how that might work. I would include source code, but so far, the line above is everything (but boilerplate) that's in the controller.php file.
Create a copy of listview in custom folder and then override the listview's listViewProcess() method and insert your query there:
function listViewProcess() // generating listview
{
$this->processSearchForm();
if($this->where==''){
$this->where.="leads.status='Converted'";
}
$this->lv->searchColumns = $this->searchForm->searchColumns;
if(!$this->headers)
return;
$this->lv->setup($this->seed, 'custom/modules/Leads/ListView/ListViewGeneric.tpl', $this->where, $this->params);
echo $this->lv->display();
}
More info: http://wiki-crm-forum.com/forum/viewtopic.php?f=2&t=9420&p=32674&hilit=listViewProcess&sid=21907ecd28734a726f61f7017a7e9a24#p32674
Another tested working example can be found here:
How to hard code the where condition in list view ,basic search,advance search in sugar CE
P.S: I'm not so sure about "v7.9 -- based loosely on Sugar 6.5 CE" I'd say it's 95% identical apart from API stuff
for custom modules in SuiteCRM.
You may change in function create_new_list_query.

Add default content to tinyMCE in Plone 5.0

I am working on a Plone 5.0 setup and I want to modify it in a way, so that users, who wants to create a new page, have a default text in their TinyMCE editor.
I am quite new to Plone and a bit overwhelmed by the amount of different languages and how they interconnect with each other. So instead of working on some files quick and dirty, I would like to have some suggestions how to start working on the problem properly and efficient.
Any suggestions, how to work on that are welcome.
The front-end (in this case TinyMCE) is not responsible for the default value, it's the form beneath.
Plone 5 uses Dexterity types with z3c forms.
EDIT: This is how your doing this the old school way - I mean the plone directives way -
Sry for misleading you. I still use plone.directives, which supports this kind of default value adapter.
The default content type Document of plone.app.contenttypes is using plone.supermodel. This has a different concept.
If you are still willing to create your own Richtext behavior you may follow those instructions: http://docs.plone.org/external/plone.app.dexterity/docs/advanced/defaults.html
In your case:
def richtext_default_value(**kwargs):
return RichTextValue('<p>Some text</p>')
#provider(IFormFieldProvider)
class IRichText(model.Schema):
text = RichTextField(
title=_(u'Text'),
description=u"",
required=False,
defaultFactory=richtext_default_value,
)
model.primary('text')
You can add a defaultFactory to the text field.
If you hack those lines on your egg, it will work.
Here's some information about setting a default value programmatically:
https://pypi.python.org/pypi/plone.directives.form#id8
How do you override the default value of a field in a dexterity behavior in Plone?
So in your case this may look something like this:
from plone.directives.form import default_value
from plone.app.contenttypes.behaviors.richtext import IRichText
from plone.app.textfield.value import RichTextValue
#default_value(field = IRichText['text'])
def richtext_default_value(data):
return RichTextValue('<p>Some text</p>')
You may extend the default_value decorator by context parameter to be more specific: #default_value(field = IRichText['text'], context=my.package.content.interfaces.IMyType)
BUT since we have the concept of behaviors it's may be better to implement your own Richtext behavior with a default value:
Creating a behavior --> http://docs.plone.org/external/plone.app.dexterity/docs/behaviors/creating-and-registering-behaviors.html AND the plone default richtext behavior as template for your own -> https://github.com/plone/plone.app.contenttypes/blob/1.2.16/plone/app/contenttypes/behaviors/richtext.py
Remove the ´plone.app.contenttypes.behaviors.richtext.IRichText` Behavior from your content type (Document) thru ZMI (portal_types -> Document)
Add your own Richtext behavior, this may be something like my.package.behaviors.richtext.IRichtextWithDefaultValue.

Trying to replace content zones in typo3

What I'm aiming to do!
I'm creating a template for a site in typo3, and i'd like to get rid of typo3's default content zones, and replace them with my own.
I.E. On the page menu.
to remove left, content, border
and to keep/add. Header. Main. Right.
The problem!
I've found snippets around the web, and bluntly, what I'm expecting to happen, isn't happening. Where every post seems to be "Thank you, great success! ++", the code I paste isn't throwing any errors, and isn't doing anything, well, at all.
My attempt
Via the typo3 documentation http://typo3.org/documentation/snippets/sd/24/
I call mod.SHARED.colPos_list in order to choose the three sections to display
t3lib_extMgm::addPageTSConfig('
mod.SHARED.colPos_list = 0,1,3
');
And I edit the TCA in extTables.php to set them to my specs.
$TCA["tt_content"]["columns"]["colPos"]["config"]["items"] = array (
"1" => array ("Header||Header||||||||","1"),
"0" => array ("Main||Main||||||||","0"),
"3" => array ("Right||Right||||||||","3"),
);
extTables.php is being called as as a die(); cuts the page.
I've cleared the cache and deleted typo3temp, logged out and in again.
But nothing happens.
My main guess, is, is this feature anything to do with templavoila? I removed it as I felt like trying out the new(er) typo3 fluid templating system, and didn't feel that I needed a GUI editor.
Any ideas?
Well - the more pages and content elements you got the more problems you will have to face when using TemplaVoila. Having comma separated values in XML structures saved to a single database field will be a performance killer as soon as you want to collect content from more than one page (uncached teaser menus or the like). Handling of references and "unused elements" is questionable as well. Of course it will work for small to medium sites, but concept wise a clean approach looks different.
Backend layouts are available since TYPO3 4.5 and work flawlessly since they just represent a normalized relation between elements and pages based on colPos. If you need more, Grid Elements will take this principle to the next level, offering even nested structures but still based on normalized relations, which will make your life much easier when it comes to DB cleaning and other maintenance tasks.
Find an introduction to backend layouts here: http://www.youtube.com/watch?v=SsxfNd4TYbk
Instead of removing default columns you can just rename them...
TIP: Use TemplaVoila extension for templating, you'll find much more flexibility there.