[TYPO3-dev] What is the best way to add custom JS events on TCA fields in BE?

Peter Klein peter at clioonline.dk
Mon Aug 22 15:07:30 CEST 2011


Hi Xavier.

With your method it's still a "user" type of field. In my situation I
would prefer to have a normal TCA/XML setup for each field.

I ended up doing it like this (it might be useful for others):

In my FlexForm Sheet I added a "form_type" = "user" after the normal
"type" tag, in order to change only the display of the field, like
this:

<form_type>user</form_type>
<userFunc>EXT:myext/class.tx_myext_flex.php:&amp;tx_myext_flex->form_type</userFunc>

Then in my "class.tx_myext_flex.php" I added a function like this:

-- cut --
public function form_type(array &$PA, t3lib_TCEforms $pObj) {

    // Add custom javascript event
    $PA['fieldChangeFunc']['test']= 'alert(\'This works\');';

    // Re-render field based on the "true field type", and not as a
"user"
    $PA['fieldConf']['config']['form_type'] =
$PA['fieldConf']['config']['type'];
    return
$pObj->getSingleField_SW($PA['table'],$PA['itemName'],$PA['row'],$PA);
}
-- cut --

--
Peter Klein





On Mon, 22 Aug 2011 12:03:27 +0200, Xavier Perseguers
<xavier at typo3.org> wrote:

>This basically is the way to go. You may have a look at some real-world 
>sample I did to add a Google Map to TCA and automatically refresh it 
>when clicking on the corresponding TCA tab (due to some overlays being 
>loaded with an invalid z-index when the Google Map is not shown when 
>loading the edit form:
>
>http://xavier.perseguers.ch/fileadmin/download/typo3/tx_climbingsites_tca_map.txt
>
>Corresponding article: 
>http://xavier.perseguers.ch/tutoriels/typo3/articles/google-map-in-tca.html
>
>HTH




More information about the TYPO3-dev mailing list