• Hello Fabrik Community

    Fabrik is now in the hands of the development team that brought you Fabrik for Joomla 4. We have recently transitioned the Fabrik site over to a new server and are busy trying to clean it up. We have upgraded the site to Joomla 4 and are running the latest version of Fabrik 4. We have also upgraded the Xenforo forum software to the latest version. Many of the widgets you might have been used to on the forum are no longer operational, many abandoned by the developers. We hope to bring back some of the important ones as we have time.

    Exciting times to be sure.

    The Fabrik 4.0 Official release is now available. In addition, the Fabrik codebase is now available in a public repository. See the notices about these in the announcements section

    We wish to shout out a very big Thank You to all of you who have made donations. They have really helped. But we can always use more...wink..wink..

    Also a big Thank You to those of you who have been assisting others in the forum. This takes a very big burden off of us as we work on bugs, the website and the future of Fabrik.

SOLVED: Change another element value based on value of dbjoin element

Status
Not open for further replies.

juuser

Well-Known Member
Hi,

I have a scenario like this:

Table Categories
elements: category_id, default_revision_time

Table Documents
elements: Categories.category_id, revision_time

If I change the databasejoin element (Categories.category_id) value on form Documents, I would need to update the "revision_time" element to "default_revision_time" from table Categories according to that particular document category.

I could retrieve this value easily with Calc element, but that doesn't allow user to select the value which is different from default.

With element Javascript I'm not capable of retrieving the needed value from Categories table.

Thanks in advance!
Martin
 
Thanks Troester, but I think that doesn't help in my case. I can get the default value from other table to the selection of my cascadingdropdown element, but I also need the user to be able to select something else than default value.

BR,
Martin
 
You'll probably need to roll your own AJAX code, using the user_ajax.php method.

Assuming revision_time is a field element ...

In this example, I'm getting the start date from an events table, and inserting it into a field element (fab_main_test___name), triggering it on a selection from the Events join dropdown ...

Create a ./components/com_fabrik/user_ajax.php file, like this:

Code:
class UserAjax
{
    /**
    * This is the method that is run. You should echo out the result you which to return to the browser
    *
    * @return  void
    */

    public function getEventDate()
    {
        $db = FabrikWorker::getDbo();
        $query = $db->getQuery(true);
        $app = JFactory::getApplication();
        $input = $app->input;
        $eventId = $input->get('eventId', '');
        $query->select('start')->from('fab_events')->where('id = ' . $db->quote($eventId));
        $db->setQuery($query, 1, 0);
        $ret = $db->loadResult();
        echo $ret;
    }
}

... and on my Event dropdown join element, I have a 'change' JS event that does this:

Code:
jQuery.ajax({
  url: 'index.php?option=com_fabrik&format=raw&task=plugin.userAjax&method=getEventDate&eventId=' + this.getValue(),
  method: 'get',
  context: this
}).done(function (r) {
  /*debugger;*/
  this.form.formElements.get('fab_main_test___name').update(r);
});

Here's it working:

https://www.screencast.com/t/NiZ6crIc9s

You'll obviously need to change the table / field / element names to suit.

-- hugh
 
Thanks, but I'm still struggling with this.

The working code that I use to retrieve the default revision time in calc element is:
PHP:
$db =& JFactory::getDBO();

$query = "SELECT a.rev_taajuus FROM prefix_laatudok_kategoriat AS a
WHERE a.id = '{prefix_laatudok_rekisteri___dokumentin_kategoria_raw}'";

$db->setQuery($query);
return $db->loadResult();


My user_ajax.php file looks like this:

PHP:
<?php
class UserAjax
{
   public function getEventDate()
    {
        $db = FabrikWorker::getDbo();
        $query = $db->getQuery(true);
        $app = JFactory::getApplication();
        $input = $app->input;
        $eventId = $input->get('dokumentin_kategoria', '');
        $query->select('rev_taajuus')->from('prefix_laatudok_kategoriat')->where('id = ' . $db->quote($eventId));
        $db->setQuery($query, 1, 0);
        $ret = $db->loadResult();
        echo $ret;
    }
}
?>

and main table category element Javscript onChange like this:

JavaScript:
jQuery.ajax({
  url: 'index.php?option=com_fabrik&format=raw&task=plugin.userAjax&method=getEventDate&eventId=' + this.getValue(),
  method: 'get',
  context: this
}).done(function (r) {
  this.form.formElements.get('prefix_laatudok_rekisteri___field_element_to_get_updated').update(r);
});

But it returns empty value :(

BR,
Martin
 
Last edited:
On the php side you are getting the wrong input. You are sending it from the JS as eventId and trying to get it in php as dokumentin_kategoria. Doesn't matter which name you use, but use the same name in both places.

Hugh

Sent from my HTC6545LVW using Tapatalk
 
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top