Support

  1. Mafketel
  2. General
  3. Wednesday, April 16 2014, 05:21 PM
Hi,

I implemented the code for the select drop down from databse table. Works great.

What I want to accomplish now is to have two drop down select next to each other, one with for example "category" and another with "sub category" (with a databasefilter on category). Obviously I need to code some ajax to live update the second drop down select, but that I can code myself.

My question: is there some fields yet that can do above functions? If not can you give me some hints on how to create such a field type?

Thanx.
admin Accepted Answer
Admin
No Sorry,
but if you hare a developer you can do this:
- create first select (category) - alias: select1
- create second select (element) - alias: select2
- add to file /administrator/components/com_jsn/hepers/fields/selectlist.php in main class this function
public static function operations()
{
if(isset($_GET['alias']))
{
// Load Field Params
$db=JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('a.*')->from('#__jsn_fields AS a')->where("a.alias = '".$_GET['alias']."'");
$db->setQuery( $query );
$field = $db->loadObject();
$registry = new JRegistry;
$registry->loadString($field->params);
$field->params = $registry;

// Create a form Object with field XML
$form=new JForm('jform');
$xml='<form>'."\n";
$xml.=JsnSelectlistFieldHelper::getXml($field);
$xml.="\n".'</form>';
$xml=new SimpleXMLElement($xml);
$form->load($xml);

// Get Input
echo($form->getField($_GET['alias'])->input);
}
}


- You must set in getOptions function (previous post) a dinamically query for select2 to get options based $_GET['catid']

- Now add Javascript: when you choose select1 you can launch a ajax request to replace select2 (without value) with new select2 (with new category value).
You must get this url: index.php?option=com_jsn&view=opField&type=selectlist&alias=select2&format=raw&catid=**select1_value_genrated_by_javascript**
with view=opField and type=selectlist Easy Profile call a 'operation' function of selectlist.

We have predict the functions for loading the fields via Ajax.;)

NOTE:
1. You must have PHP Knowledge
2. We do not give support for these changes
  1. more than a month ago
  2. General
  3. # 1
Mafketel Accepted Answer
Hi, I have php knowledge and I think I must be able to code this. Thanks for pointing me in the right direction. I am going to start and try to work it out.
  1. more than a month ago
  2. General
  3. # 2
Mafketel Accepted Answer
Content Protected
  1. more than a month ago
  2. General
  3. # 3
admin Accepted Answer
Admin
Sorry for late reply
It's late for us and our office closed.

Please post me your site link to check javascript code and getoption function that you have implemented.

Also please specify a valid catid parameter to insert in http query.
  1. more than a month ago
  2. General
  3. # 4
admin Accepted Answer
Admin
Hi,
today we will release new version with get option from DB feature for selectlist. we will send you a code to do this (tested and work).;)
  1. more than a month ago
  2. General
  3. # 5
Mafketel Accepted Answer
Hi,
Thank you that is good news. I was setting up a test site for you to connect to. I will continue setting this up but will wait for the update/code before I do more testing.
Thanks
  1. more than a month ago
  2. General
  3. # 6
admin Accepted Answer
Admin
Hi, in download area you get the new version 1.2.5

Follow these step:
add to file /administrator/components/com_jsn/hepers/fields/selectlist.php (replace the where of query, see comment)
public static function operations()
{
if(isset($_GET['alias']))
{
// Load Library
JFormHelper::addFieldPath(JPATH_ADMINISTRATOR.'/components/com_jsn/models/fields');

// Load Field Params
$db=JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('a.*')->from('#__jsn_fields AS a')->where("a.alias = '".$_GET['alias']."'");
$db->setQuery( $query );
$field = $db->loadObject();
$registry = new JRegistry;
$registry->loadString($field->params);
$field->params = $registry;

// Create a form Object with field XML
$form=new JForm('jform',array('control' => 'jform'));
$xml='<form>'."\n";
$xml.=JsnSelectlistFieldHelper::getXml($field);
$xml.="\n".'</form>';
$xml=new SimpleXMLElement($xml);
$form->load($xml);

// Set Where From HTTP
$form->setFieldAttribute($_GET['alias'], 'dboptwhere','state=1 AND catid='.$_GET['catid']); // replace 'state=1 AND catid='.$_GET['catid'] with your query

// Get Input
echo($form->getField($_GET['alias'])->input);
}
}


add this javascript to your jQuery(document).ready() (replace selectAlias1 with your select category alias and selectAlias2 with your select value alias, maybe replace $ with jQuery )
$('#jform_selectAlias1').change(function(){
$.ajax({
url : "index.php?option=com_jsn&view=opField&type=selectlist&alias=selectAlias2&format=raw&catid="+$(this).val(),
success : function (data,state) {
var val=$('#jform_selectAlias2').attr('data-val');
$('#jform_selectAlias2').parent().html(data);
$('#jform_selectAlias2').val(val).attr('data-val',val);
$('#jform_selectAlias2').chosen();

}
})
});
$('#jform_selectAlias1').change();


My test:
I have created select 1 with this parameter:
condition 1: if equal to custom value (empty) hide select 2 // if this field is empty not show select 2
table: #__categories
column value: id
column text: title
sql where: extension='com_content' AND published=1 //because #__categories contains all category not only for article

I have created select 2 with this parameter
table: #__content
column value: id
column text: title
sql where: id=0 //because otherwise you load all record of table before filter by category, this is not a problem but weighs down the page to load
  1. more than a month ago
  2. General
  3. # 7
Mafketel Accepted Answer
Hi, thanks. I got this working now. I am going to adjust because there will be a few more of this pairs of dependant dropdown select lists.

I am also looking to place the two dropdown select lists next toeach other (on the same line). I am trying to sort it out myself, but if you have any hints/tips it would be appreceated.
  1. more than a month ago
  2. General
  3. # 8
admin Accepted Answer
Admin
Hi,
I would do it with CSS/Javascript code,
example:
the privacy field is nothing more than a normal field with its own dedicated line.
You can check our Javascript code for privacy in components/com_jsn/assets/js/privacy.js (in line 3 and 4 we assign a class privacy to row of each privacy field),
in components/com_jsn/assets/css/style.css you can find our solution to make it stand on the same line of assigned field.
  1. more than a month ago
  2. General
  3. # 9
Mafketel Accepted Answer
Hi, I got things working now. I created some component-overrides. I did some tricks on positioning fields and I use my own naming convention subcategory_1 always co-exists with category_1 This way I can add as many category subcategory combo's as I want.
I used some code from he jquery example you provided (I just repeat it on a need to have basis in the php-script)
So, thanks for your help.
  1. more than a month ago
  2. General
  3. # 10
Mafketel Accepted Answer
Hi,

It has been a while since last post, but I started working on thiss website again and now I have a follow up question. I post it here because I think that it is helpful to see history.

The above scenario/script works like it is intended. I want to add some functionality and for that I need to capture the .change event from the second dropdown.

When I prefill the second list from php I can catch the change event in jquery. But when I change the first select and fill the second from code the change event does not get fired for some reason.

Do you have any ideas why?

Thanks
  1. more than a month ago
  2. General
  3. # 11
admin Accepted Answer
Admin
Hi,
after this
$('#jform_selectAlias2').chosen();

try to put this code to fire second select
$('#jform_selectAlias2').change();
  1. more than a month ago
  2. General
  3. # 12
  • Page :
  • 1


There are no replies made for this post yet.
However, you are not allowed to reply to this post.
Sorry, the discussion is currently locked. You will not be able to post a reply at the moment.

Request Support

Support is currently Offline

Support Availability

Working days: Monday to Friday. The support staff is not available on weekends; in the most of cases tickets will not be answered during that time.

Reply time: Depending on the complexity of your support issue it's usually between a few minutes and 24 hours for paid members and about one week for free members. When we expect longer delays we will notify you.

Guidelines

Before you post: read the documentation and search the forums for an answer to your question.

When you post: include Site Details if you request a support (you can use the form below the reply in Site Details tab).

Auto Solved Question: If after a week the author of the post does not reply to a request by moderator, the question will be marked as resolved.

Language: only English

Search Users

Easy Profile® is not affiliated with or endorsed by Open Source Matters or the Joomla Project. Joomla is Free Software released under the GNU/GPL License.