[TYPO3-english] chained selectbox in typo3 backend (ajax)

Sven Juergens t3 at blue-side.de
Thu Sep 9 19:46:41 CEST 2010


Am 09.09.10 18:49, schrieb Sergey Alexandrov:
> Ok,
>
> 1. add to ext_localconf.php something like this:
>
> $TYPO3_CONF_VARS['BE']['AJAX']['your_ext::getDepartments'] =
> 'EXT:your_ext/class.ajax_response.php:tx_yourext_ajax->_ajax_get_departments
> ';
>
> 2. Create class.ajax_response.php, something like:
>
> class tx_yourext_ajax
> {
>          function ->_ajax_get_departments($params,&$ajaxObj)
>          {
>                  global $TYPO3_DB;
> 			// Get AJAX params, as an example
>                  $cid = intval(t3lib_div::_GP('coid'));
>                  $res = $TYPO3_DB->exec_SELECTgetRows(
>                      'depname',
>                      'deptable',
>                      "uid=$cid and deleted = 0 and hidden = 0"
>                  );
> 		   foreach ($res as $qq)
>                  {
> 			// You can return<options value....>  here, this
> will return just depnames in plain text, separated by comma :)
>                      $ajaxObj->addContent('', $qq['depname'].',');
>                  }
>                  return true;
>          }
> }
>
> 3. Include prototype into plugin's main()
> $GLOBALS['TSFE']->additionalHeaderData["js"] = '<script
> language="javascript" src="/typo3/contrib/prototype/prototype.js"
> type="text/javascript"></script>';
>
> 4. Tricky part, now it's up to you to javascript :) You will have to create
> a javascript code to handle requests - for example:
>
>          function JustDoIt(obj)
>          {
>                  new Ajax.Updater('departments','/typo3/ajax.php', {
>                      method: 'post',
>                      parameters:
> 'ajaxID=your_ext::getDepartments&coid='+obj.id,
>                      onComplete: function(xhr, json)
>                      {
>                          //alert('Response: '+xhr.responseText);
>                      }.bind(this),
>                      onT3Error: function(xhr, json)
>                      {
>                          alert('Error occured: '+xhr.responseText);
>                      }.bind(this)
>                  });
>
>          }
>
> But this one will update HTML element with ID='departments', you have to
> update select, so you can use Ajax.Request instead, and then do
> manipulations with the select's options
>
> 5. Oh, in plugin output you should use smth. like below to envoke ajax
> request
>
> <select id="whatever" onchange='JustDoIt(this)'>.....</select>
>
> 6. BTW, there is typo3/contrib/scriptaculous/builder.js which will help you
> to build HTML elements with javascript
>
> Hope this help
>
> -----Original Message-----
> From: typo3-english-bounces at lists.typo3.org
> [mailto:typo3-english-bounces at lists.typo3.org] On Behalf Of Jochem Nabuurs
> Sent: Thursday, September 09, 2010 11:51 AM
> To: typo3-english at lists.typo3.org
> Subject: [TYPO3-english] chained selectbox in typo3 backend (ajax)
>
> Hi List,
>
> I have an extension which allows editors to add employees.
> Editors must fill in fields like name, address, etc but also the
> selectboxes unit, main departement, departement and subdepartement.
>
> When a unit is selected, the selectboxes with main departement,
> departement and subdepartement must change accordingly.
>
> I'd like to do this with ajax calls but I don't know where to start.
> I've build my extension with the kickstarter, which does not provide
> ajax based selectboxes (AFAIK).
>
> Is it at all possible? I've read an article about ajax functionality in
> TYPO3 backend but I can't seem to figure out how to integrate it in my
> extension. Are there any extensions available which also provide the
> functionality I described?
>
> I'm running TYPO3 4.3.2 in my test environment, but the live site runs
> 4.4.2. I know this is not advised but it's the only option for now.
>
> The article I've read is located here:
> http://typo3.org/documentation/document-library/core-documentation/doc_core_
> api/4.2.0/view/3/9/
>
>
> I hope someone can point me in the right direction.
>
> Thanks in advance!
>
> Jochem Nabuurs
> _______________________________________________
> TYPO3-english mailing list
> TYPO3-english at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-english
>


hi,

i like the idea of ajax based selectboxes too and your tip is very 
interesting :).
But how it's possible to give that specific selectbox from TYPO3 an own ID ?

best regards
Sven


More information about the TYPO3-english mailing list