Most Common mistake with sub-palettes
You've added the __selector__, subpalette, and the submitOnChange field, but your sub-palette doesn't show up?
:?: This is by far the most common mistake developer's make. What's the answer?
:!: You simply forgot to add the selector in the database.sql file (or you haven't updated the database to create the field).
The problem occurs in when the checkbox is changed, and then the DB value is set/retrieved, and of course the DB field doesn't exist, so the value cannot change to "checked".
Re: Most Common mistake with sub-palettes
Does documentation already exist regarding data type definitions for Contao?
Ie of the form:
[database.sql - Selectors]
Datatype: char(1) NOT NULL default ''
And similarly for other fields such as keys.
I know this stuff is found out by looking through existing Contao code, but a full and extensive reference would be handy to new & existing devs.
For new dev's, maybe more examples on developing certain features in Contao. Platforms such as Django have good docs on getting a developer started without looking through lots of example code.
/hijack
Re: Most Common mistake with sub-palettes
have you read through the developer guide?
all types of table editing "examples" are in use in the Contao core, e.g. stylesheets, modules, articles and/or news. These form the basis of all module and the way they are coded. TL doesn't have a standard DB field for each datatype, as you can vary the datatype considerably with parameters, so you have to make an adjustment to the DB field to accomodate your changes.
Bascially:
char(1) - checkboxes
int(10) - for dates, ID values (id, pid)
smallint(5) - for small integer values (like 10 items per page),
varchar(32) - varchar(255) for select fields with character values, and also for text fields
text NULL - for descriptions
blob NULL - for serializes checkboxes and other large datatypes
Re: Most Common mistake with sub-palettes
and if we want just to display the subpalette without updating the database => if I check the checkbox of the selector, the subpalette appears before storing to the database, how should we do?
Thank you
Re: Most Common mistake with sub-palettes
There is no way. Contao always updates the database when loading a subpalette :)
But that doesn't really matter, does it?
Re: Most Common mistake with sub-palettes
Quote:
Originally Posted by Toflar
There is no way. Contao always updates the database when loading a subpalette :)
But that doesn't really matter, does it?
=> yes, when we change a field and we find a new item in the database :-)
also with the required fields, the error message appears every time ...
Re: Most Common mistake with sub-palettes
true, i've changed fields that i would like to be mandatory into non-mandatory because of this...
i've not discovered a way around it.
Re: Most Common mistake with sub-palettes
Yes, this is the usual Contao behaviour :)
Re: Most Common mistake with sub-palettes
My subpalettes are initially all opened! but the checkbox (__selector__) is unchecked!
If I then click once on the __selector__, checkbox remains unchecked and subpalettes are hidden. There after it behaves right. Have you guys got any idea!
DCA
Code:
$GLOBALS['TL_DCA']['tl_content']['fields']['tm_controlsEnabled'] = array
(
'label' => &$GLOBALS['TL_LANG']['tl_content']['tm_controlsEnabled'],
'exclude' => true,
'inputType' => 'checkbox',
'eval' => array('submitOnChange'=>true)
);
Code:
$GLOBALS['TL_DCA']['tl_content']['palettes']['__selector__'][] = 'tm_controlsEnabled';
$GLOBALS['TL_DCA']['tl_content']['subpalettes']['tm_controlsEnabled'] = 'tm_controlColor,tm_controlBackColor';
Database field
Code:
`tm_controlsEnabled` char(1) NOT NULL default '',
Re: Most Common mistake with sub-palettes
Hi Tsarma, I have run into this before... in my case it was caused by using 'default' => false in the checkbox field description.
I put in a ticket but Leo marked it as invalid. http://dev.contao.org/issues/2370
Not sure with you though... what is your ['palettes']['default'] ??
Re: Most Common mistake with sub-palettes
Hi Ramjet, Thanks for the tip.
I tried with 'default' => '0' or without the 'default', and Since in your case 'default' => false lead to the problem, this gave me the idea to put 'default' => '', and now it works.
So the correct way for me to go is
Code:
$GLOBALS['TL_DCA']['tl_content']['fields']['tm_controlsEnabled'] = array
(
'label' => &$GLOBALS['TL_LANG']['tl_content']['tm_controlsEnabled'],
'exclude' => true,
'inputType' => 'checkbox',
'default' => '',
'eval' => array('submitOnChange'=>true)
);
Re: Most Common mistake with sub-palettes
Re: Most Common mistake with sub-palettes
Hi,
I have the same probleme with a "select"
i don't find the error !
this my dca > tl_sale_sector.php
Code:
$GLOBALS['TL_DCA']['tl_sale_sector'] = array
(
// Config
'config' => array
(
'dataContainer' => 'Table',
'ctable' => array('tl_sale_sector_elements'),
'switchToEdit' => true,
'enableVersioning' => true
),
// List
'list' => array
(
'sorting' => array
(
'mode' => 1,
'fields' => array('sector_type'),
'flag' => 1,
'panelLayout' => 'filter;search,limit'
),
'label' => array
(
'fields' => array('sector_type'),
'format' => '%s',
'label_callback' => array('tl_sale_sector', 'details_saler')
),
'global_operations' => array
(
'all' => array
(
'label' => &$GLOBALS['TL_LANG']['MSC']['all'],
'href' => 'act=select',
'class' => 'header_edit_all',
'attributes' => 'onclick="Backend.getScrollOffset();"'
)
),
'operations' => array
(
'edit' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_sale_sector']['edit'],
'href' => 'act=edit',
'icon' => 'edit.gif'
),
'copy' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_sale_sector']['copy'],
'href' => 'act=copy',
'icon' => 'copy.gif'
),
'delete' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_sale_sector']['delete'],
'href' => 'act=delete',
'icon' => 'delete.gif',
'attributes' => 'onclick="if (!confirm(\'' . $GLOBALS['TL_LANG']['MSC']['deleteConfirm'] . '\')) return false; Backend.getScrollOffset();"'
),
'show' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_sale_sector']['show'],
'href' => 'act=show',
'icon' => 'show.gif'
)
)
),
// Palettes
'palettes' => array
(
'default' => '{type_legend},sector_type',
'Continent' => '{type_legend},sector_type;{state_legend},sector_name',
'Pays' => '{type_legend},sector_type;{state_legend},sector_name',
'Departements' => '{type_legend},sector_type;{country_legend},sector_name,sector_number'
),
// Fields
'fields' => array
(
'sector_type' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_sale_sector']['sector_type'],
'default' => 'Continent',
'exclude' => true,
'filter' => true,
'inputType' => 'select',
'options' => array('Veuillez choisir le type secteur', 'Departements', 'Pays', 'Continent'),
'eval' => array('mandatory'=>false, 'submitOnChange'=>true)
),
'sector_name' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_sale_sector']['sector_name'],
'exclude' => true,
'search' => true,
'inputType' => 'text',
'eval' => array('mandatory'=>true, 'maxlength'=>10, 'feEditable'=>true, 'feViewable'=>true, 'tl_class'=>'w50')
),
'sector_number' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_sale_sector']['sector_number'],
'exclude' => true,
'search' => true,
'inputType' => 'text',
'eval' => array('mandatory'=>true, 'maxlength'=>10, 'feEditable'=>true, 'feViewable'=>true, 'tl_class'=>'w50')
)
)
);
class tl_sale_sector extends Backend
{
/*----- label_callback -----------------------------------------------------------------*/
/**
*
* List a Saler
*
*/
public function details_saler($arrRow, $strLabel)
{
$objElements = $this->Database->prepare("SELECT * FROM tl_list_feature_elements WHERE pid=? ORDER by sorting ASC")
->execute($arrRow['id']);
if ($objElements->numRows > 0)
{
while ($objElements->next())
{
if (strncmp($objElements->id, '.', 1) === 0)
{
continue;
}
}
}
else
{
$OutputImages = $GLOBALS['TL_LANG']['tl_list_feature']['misc_noimages'];
}
return '<div class="labelbox">
<div class="heading">' . $arrRow['sector_name'] . ' ' . $arrRow['sector_number'] . '</div>
<div style="margin-left:40px;" class="limit_height block">
Ce secteur compte ' . count($arrElements) . ' contact(s) :
</div>
</div>';
}
}
Re: Most Common mistake with sub-palettes
Hi tom-over,
A "selector" merely opens and closes a "subpalette", and is normally a checkbox.
For example here I'm opening up 4fields 'singleSRC,alt,imagesize,fullsize' when 'addplaylistimage' is checked.
Code:
// Palettes
'palettes' => array
(
'__selector__' => array('addplaylistimage'),
'default' => 'showit;listtitle,listdescription;playlisttype,forcefiletype;{filenameLegend},name;{feedselectLegend},destination,localxml,remotefeed;{listImageLegend:hide},addplaylistimage'
),
//Sub Palettes
'subpalettes' => array
(
'addplaylistimage' => 'singleSRC,alt,imagesize,fullsize'
),
I think what you're trying to do is show a different palette based on each of 4 choices in "sector_type" ... yes?
You could use an onsubmit callback to do this - to rewrite the palette with your submitOnChange in your 'sector_type' field.
You are then calling a function to string-replace the palette based on an if condition.
An example of a function called by onsubmit_callback... This looks at the value of a select menu called 'playlisttype' and
replaces the palette accordingly...
I wrote this before $dc->activeRecord->playlisttype was invented, so you shouldn't need to do a database call to get the value of your select menu.....
Code:
public function changePalette($dc)
{
$objPalette = $this->Database->prepare("SELECT playlisttype FROM tl_playlist WHERE id=?")
->limit(1)
->execute($dc->id);
if($objPalette->playlisttype == "LocalXML")
{
$GLOBALS['TL_DCA']['tl_playlist']['palettes']['default'] = str_replace('showit;listtitle,listdescription;playlisttype,forcefiletype;{filenameLegend},name;{feedselectLegend},destination,localxml,remotefeed;{listImageLegend:hide},addplaylistimage', 'showit;listtitle,listdescription;playlisttype;{feedselectLegend},localxml;{listImageLegend:hide},addplaylistimage', $GLOBALS['TL_DCA']['tl_playlist']['palettes']['default']);
//need to make saveN buttons return correctly HERE
}elseif($objPalette->playlisttype == "RemoteFeed")
{
$GLOBALS['TL_DCA']['tl_playlist']['palettes']['default'] = str_replace('showit;listtitle,listdescription;playlisttype,forcefiletype;{filenameLegend},name;{feedselectLegend},destination,localxml,remotefeed;{listImageLegend:hide},addplaylistimage', 'showit;listtitle,listdescription;playlisttype;{feedselectLegend},remotefeed;{listImageLegend:hide},addplaylistimage', $GLOBALS['TL_DCA']['tl_playlist']['palettes']['default']);
//need to make saveN buttons return correctly HERE
}else
{
$GLOBALS['TL_DCA']['tl_playlist']['palettes']['default'] = str_replace('showit;listtitle,listdescription;playlisttype,forcefiletype;{filenameLegend},name;{feedselectLegend},destination,localxml,remotefeed;{listImageLegend:hide},addplaylistimage', 'showit;listtitle,listdescription;playlisttype,forcefiletype;{filenameLegend},name;{feedselectLegend},destination;{listImageLegend:hide},addplaylistimage', $GLOBALS['TL_DCA']['tl_playlist']['palettes']['default']);
//saveN buttons return correctly OK
}
}
Write out your whole palette for 'default' => '{type_legend},sector_type'....
Then in each If the formular is
Code:
if(field==A)
{
$GLOBALS['TL_DCA'][xxx]['palettes']['default'] = str_replace('myWholePalette', 'theA-PaletteIWant', $GLOBALS['TL_DCA'][xxx]['palettes']['default']);
}elseif(field==B)
{
$GLOBALS['TL_DCA'][xxx]['palettes']['default'] = str_replace('myWholePalette', 'theB-PaletteIWant', $GLOBALS['TL_DCA'][xxx]['palettes']['default']);
}
hope this makes sense.
Re: Most Common mistake with sub-palettes
Just look at the MODULE, NEWS, EVENTS or CONTENT palettes, as they all have a primary type selector to display multiple types of fields depending on the type, e.g. When you select a Newslist module in MODULE, then the Newslist palette is shown. Basically a nice way to group the DB fields in your table, for a variety of entries.
Re: Most Common mistake with sub-palettes
@tom-over
if you want to use select as selector (instead of checkbox) take a look at http://dev.contao.org/issues/1156
Re: Most Common mistake with sub-palettes
I have forget the selector ! ;)
Code:
'__selector__' => array('sector_type'),
Re: Most Common mistake with sub-palettes
Quote:
Originally Posted by thyon
have you read through the developer guide?
all types of table editing "examples" are in use in the Contao core, e.g. stylesheets, modules, articles and/or news. These form the basis of all module and the way they are coded. TL doesn't have a standard DB field for each datatype, as you can vary the datatype considerably with parameters, so you have to make an adjustment to the DB field to accomodate your changes.
Bascially:
char(1) - checkboxes
int(10) - for dates, ID values (id, pid)
smallint(5) - for small integer values (like 10 items per page),
varchar(32) - varchar(255) for select fields with character values, and also for text fields
text NULL - for descriptions
blob NULL - for serializes checkboxes and other large datatypes
and if we want just to display the subpalette without updating the database => if I check the checkbox of the selector, the subpalette appears before storing to the database, how should we do?
Thank you
Re: Most Common mistake with sub-palettes
You can't have nonDB fields in the DCA. All fields must be created, even if you never store anything in them.
Re: Most Common mistake with sub-palettes
Quote:
Originally Posted by thyon
You can't have nonDB fields in the DCA
fields created with input_field_callback can be nonDB fields
Re: Most Common mistake with sub-palettes
If the field is used anywhere in Search, Filter in the header you're screwed, as the table driver loads directly from the DB.
Re: Most Common mistake with sub-palettes
Quote:
Originally Posted by thyon
If the field is used anywhere in Search, Filter in the header you're screwed, as the table driver loads directly from the DB.
sure :) I just want to point out that if you know what you are doing you can have nondb fields.