Jump to content


Simple dependant dropdown extension

dropdown select dependancy relation date filetring ajax

  • Please log in to reply
85 replies to this topic

#21 Gil29MX

Gil29MX

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 16 August 2013 - 06:45 PM

Hello Assem, just try open the ajax_grocery_CRUD file and chance $state_code from private to protected in the line 6



#22 Amit Shah

Amit Shah

    grocery CRUD Master

  • Advanced Member
  • PipPipPip
  • 1,192 posts
  • LocationMumbai, India

Posted 21 August 2013 - 03:13 PM

Hi there,

 

Updated the ajax grocery crud library.

 

The earlier version was written with GC 1.3.3. When used it with version 1.4 - it started giving error for $state_code .. in version 1.4 the state_code is set to be protected.

 

Secondly what other thing i noticed was that both for source and target, the fields initially were selectable. That is where i thought of updating a bit. Now initially the target is disabled. Only when the user selects the source, the target will be enabled.

 

Other thing noticed .. liszt:update for some reason was failing to work with the latest version of chosen if downloaded. So altered the code there too.

 

Happy GCing..

Attached Files



#23 davidoster

davidoster

    Grocery CRUD Ninja

  • Advanced Member
  • PipPipPip
  • 1,068 posts
  • LocationAthens, Greece

Posted 22 August 2013 - 12:56 AM

Hi there,

 

Updated the ajax grocery crud library.

 

The earlier version was written with GC 1.3.3. When used it with version 1.4 - it started giving error for $state_code .. in version 1.4 the state_code is set to be protected.

 

Secondly what other thing i noticed was that both for source and target, the fields initially were selectable. That is where i thought of updating a bit. Now initially the target is disabled. Only when the user selects the source, the target will be enabled.

 

Other thing noticed .. liszt:update for some reason was failing to work with the latest version of chosen if downloaded. So altered the code there too.

 

Happy GCing..

Is this latest updated version works also with 1.3.3?


____________________________________________________________

 

rtfm_small.jpg---!!!Please read these guidelines before asking to the forums!!!---

____________________________________________________________

 

David Oster aka George Pasparakis,
http://odphotography.com
http://eletter.gr


#24 Amit Shah

Amit Shah

    grocery CRUD Master

  • Advanced Member
  • PipPipPip
  • 1,192 posts
  • LocationMumbai, India

Posted 22 August 2013 - 08:26 AM

Well i should admit that the newer version i updated dose not work with the default version supplied in GC 1.3.3. But if replaced with the latest version of jquery  chosen then this library altered works fine. The latest jquery chosen has some bug fixes.. it is compatible with jquery 1.9 ... the earlier version is not. There are a few functions that are obsolated from the earlier ones.



#25 davidoster

davidoster

    Grocery CRUD Ninja

  • Advanced Member
  • PipPipPip
  • 1,068 posts
  • LocationAthens, Greece

Posted 23 August 2013 - 08:35 AM



Well i should admit that the newer version i updated dose not work with the default version supplied in GC 1.3.3. But if replaced with the latest version of jquery  chosen then this library altered works fine. The latest jquery chosen has some bug fixes.. it is compatible with jquery 1.9 ... the earlier version is not. There are a few functions that are obsolated from the earlier ones.

 

Hmmm! Ok! Thanks, Amit Shah.


____________________________________________________________

 

rtfm_small.jpg---!!!Please read these guidelines before asking to the forums!!!---

____________________________________________________________

 

David Oster aka George Pasparakis,
http://odphotography.com
http://eletter.gr


#26 hkgeeks

hkgeeks

    Newbie

  • Members
  • Pip
  • 5 posts

Posted 27 August 2013 - 05:12 PM

Hi there,

 

i am using  GC 1.4 and tried Amit Shah version of ajax_grocery_crud, follow the sample from the first page, it occurs a problem, I have a loo on the response post data like the attached file, its look like correct data, but the "Ad state id" still can select other options, how can i fix it?

 

Thank you for helping

Attached Thumbnails

  • Untitled-2.jpg


#27 Amit Shah

Amit Shah

    grocery CRUD Master

  • Advanced Member
  • PipPipPip
  • 1,192 posts
  • LocationMumbai, India

Posted 28 August 2013 - 09:32 AM

Well hkgeeks

If you read up, it is more to do with the latest version of choosen library and not with Grocerycrud.. the latest version of choosen is good if you want to use jquery 1,9 and above cuz post jquery 1.8.x they have eliminated a certain set of functionalities. Hence will recommend to update the latest version of choosen to get the best results with the code updated.

Else will be best to go with the older version of library.



#28 adauri_jr

adauri_jr

    Newbie

  • Members
  • Pip
  • 1 posts
  • LocationBrazil

Posted 03 September 2013 - 02:02 AM

Hello, I'm using the grocery 1.33, when I use the class ajax_grocery_CRUD is inserted a blank line at the beginning of the site, someone can tell me why?

 

thank you

Attached Thumbnails

  • no_ajax.png
  • ajax.png


#29 hiperjp

hiperjp

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 04 September 2013 - 04:00 PM

Hi,

I'm having this error:

 

Where on grocery crud v1.3.3 and previous version of your extension was working, currently I'm on GC v1.4.1 and your last version posted on ago-21. This is related to those jQuery 1.9 issues that you have described? :)
 
This error occurs when I select an option in first select field on two-chained selects.
 
Thank you!
 
EDIT1: In previous version, the ajax URL is: /backend/programas/index/edit/ajax_extension/sede_id/institucion_id/1, without the domain and with obvious missing parameters.  :)


#30 palme

palme

    Newbie

  • Members
  • Pip
  • 7 posts

Posted 17 September 2013 - 12:09 PM

Hi Ricardo. As I could do to relate an element of the category and subcategory that are in the same table?

 

Hola Ricardo. Como yo podría hacer para relacionar un elemento del tipo categoría y subcategoria que estén en la misma tabla?

CREATE TABLE categories ( 
     id INT PRIMARY KEY,
     name VARCHAR(50),
     parent_id INT,
);

CREATE TABLE post ( 
     id INT PRIMARY KEY,
     category_id INT,
     subcategory_id INT,
     name VARCHAR(50),
);

Intente de esta manera

Thus try

 

$crud->set_relation('category_id','categories','name');
$crud->set_relation('subcategory_id','categories','name');

$crud->set_relation_dependency('subcategory_id','category_id','parent_id');

 

Thank you very much for the contribution

Muchas gracias por el aporte

 



#31 Bukky

Bukky

    Newbie

  • Members
  • Pip
  • 2 posts
  • LocationKerala, India

Posted 18 September 2013 - 09:42 AM

Hi All,

 

For me the awesome ajax grocery crud not working correctly, am using latest version of GC (1.4.1), Using firebug I can see that Ajax request and Response are working fine, But value is not updating in 'select', I hope that it is some problem with CHOSEN plugin. Please help with a work around.



#32 Prasanth Mathew

Prasanth Mathew

    Newbie

  • Members
  • Pip
  • 1 posts
  • LocationCochin

Posted 18 September 2013 - 10:20 AM

@bukky

 

Please change trigger('chosen:updated') to  trigger("liszt:updated") on function 'render_relation_dependency' in  ajax_grocery_crud.php file

 

 

private function render_relation_dependency($target_field, $source_field, $relation_field_on_source_table){


$sourceElement = "'#field-$source_field'";
$targetElement = "'#field-$target_field'";


$js_text = "
$(document).ready(function() {
$($targetElement).attr('disabled', true).trigger('liszt:updated');
$($sourceElement).change(function() {
$($targetElement).attr('disabled', false).trigger('liszt:updated');
var selectedValue = $($sourceElement).val();
if(selectedValue == '') {
$($targetElement).val('');
$($targetElement).attr('disabled', true).trigger('liszt:updated');
}
//alert('selectedValue'+selectedValue);
//alert('post:'+'ajax_extension/$target_field/$relation_field_on_source_table/'+encodeURI(selectedValue.replace(/\//g,'$this->slash_replacement')));
$.post('ajax_extension/$target_field/$relation_field_on_source_table/'+encodeURI(selectedValue.replace(/\//g,'$this->slash_replacement')), {}, function(data) {
var \$el = $($targetElement);
 var newOptions = data;
 \$el.empty(); // remove old options
 console.log(\$el);
 console.log('Emptied up the elements');
 \$el.append(\$('<option></option>').attr('value', '').text(''));
 \$.each(newOptions, function(key, value) {
   \$el.append(\$('<option></option>')
      .attr('value', key).text(value));
   });
 //\$el.attr('selectedIndex', '-1');
 \$el.chosen().trigger('liszt:updated');


        },'json');
        $($targetElement).change();
});
});
";


$this->inline_js($js_text);


}

I think this will solve your problem



#33 Bukky

Bukky

    Newbie

  • Members
  • Pip
  • 2 posts
  • LocationKerala, India

Posted 18 September 2013 - 10:29 AM

 

@bukky

 

Please change trigger('chosen:updated') to  trigger("liszt:updated") on function 'render_relation_dependency' in  ajax_grocery_crud.php file

 

 

private function render_relation_dependency($target_field, $source_field, $relation_field_on_source_table){


$sourceElement = "'#field-$source_field'";
$targetElement = "'#field-$target_field'";


$js_text = "
$(document).ready(function() {
$($targetElement).attr('disabled', true).trigger('liszt:updated');
$($sourceElement).change(function() {
$($targetElement).attr('disabled', false).trigger('liszt:updated');
var selectedValue = $($sourceElement).val();
if(selectedValue == '') {
$($targetElement).val('');
$($targetElement).attr('disabled', true).trigger('liszt:updated');
}
//alert('selectedValue'+selectedValue);
//alert('post:'+'ajax_extension/$target_field/$relation_field_on_source_table/'+encodeURI(selectedValue.replace(/\//g,'$this->slash_replacement')));
$.post('ajax_extension/$target_field/$relation_field_on_source_table/'+encodeURI(selectedValue.replace(/\//g,'$this->slash_replacement')), {}, function(data) {
var \$el = $($targetElement);
 var newOptions = data;
 \$el.empty(); // remove old options
 console.log(\$el);
 console.log('Emptied up the elements');
 \$el.append(\$('<option></option>').attr('value', '').text(''));
 \$.each(newOptions, function(key, value) {
   \$el.append(\$('<option></option>')
      .attr('value', key).text(value));
   });
 //\$el.attr('selectedIndex', '-1');
 \$el.chosen().trigger('liszt:updated');


        },'json');
        $($targetElement).change();
});
});
";


$this->inline_js($js_text);


}

I think this will solve your problem

 

 

Thank you Prasanth, It's working fine now....



#34 archerwisdom

archerwisdom

    Advanced Member

  • Members
  • PipPipPip
  • 36 posts

Posted 08 October 2013 - 03:49 PM

Appreciate if someone can post his/her working example using this ajax_grocery_crud.



#35 Koia

Koia

    Member

  • Members
  • PipPip
  • 10 posts

Posted 26 October 2013 - 09:11 AM

Hello,

 

Thanks for the extremely simple to use ajax_grocery_crud.php library. Awsome indeed and, in particular being a newbee, the simplicity has saved me a lot of time.

 

The library works fine in my application with Add Record. But a little problem as usual!

 

When editing an existing record the parent and child dropdown texts in the edit view correspond to the content of the database but the records available for editorial choise in the child dropdown are taken from the whole dependant table and not only from those records corresponding to the parent dropdown choise.

 

Due to this problem it is possible to combine parent and child datatable records in a not adequate way and save them with content errors as a consequence.

 

I am in GC 1.3.3. My ajax_grocery_crud.php file was posted here on April 15.

 

 

Hope someone can help! Thanks in advance!



#36 davidoster

davidoster

    Grocery CRUD Ninja

  • Advanced Member
  • PipPipPip
  • 1,068 posts
  • LocationAthens, Greece

Posted 10 November 2013 - 06:13 AM

Hello and welcome to the forums Koia.

If you have downloaded this then try to update your version of GC to the latest stable 1.4.1 to see if this problem still happens.


____________________________________________________________

 

rtfm_small.jpg---!!!Please read these guidelines before asking to the forums!!!---

____________________________________________________________

 

David Oster aka George Pasparakis,
http://odphotography.com
http://eletter.gr


#37 Koia

Koia

    Member

  • Members
  • PipPip
  • 10 posts

Posted 12 November 2013 - 07:49 PM

Hello, thanks for reply. I installed CI 2.1.3 and GC 1.4.1. Unfortunatly the ajax_grocery_CRUD library did not load. It gets stuck on ci_load_class function on line 973 when calling include_once cunction.



#38 Mateus Machado

Mateus Machado

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 23 November 2013 - 03:59 AM

First, thanks a lot for this great code.

 

I can't make it work here. Could you update the first post with latest code to download? No errors, but the dropdowns aren't interconnected as waited.



#39 kuaskada

kuaskada

    Member

  • Members
  • PipPip
  • 13 posts

Posted 12 May 2014 - 07:36 AM

Hello!!

 

I'm a spanish student and it's my first message.

 

I'm trying to use this library, but it doesn't work. I have a table of products, and the products have a categorie and a subcategorie. This is my example:

 

TABLE products: (id_prod, nombre_prod, prod_id_cat, prod_id_subcat)

TABLE categories: (id_cat, nombre_cat)

TABLE subcategories: (id_subcat, nombre_subcat, subcat_id_cat)

 

I'm using two relations:

 

set_relation('prod_id_cat', 'categories', 'nombre_cat);

set_relation('prod_id_subcat', 'subcategories', 'nombre_subcat');

 

The relations work correctly.

 

When i try use de relation_dependency, it doesn't work. 

 

set_relation_dependency('prod_id_cat', 'prod_id_subcat', 'subcat_id_cat');

 

You can select the subcategorie before choose the categorie, and when I select a categorie, i can select all subcategories.

 

relation_dependency.jpg

 

 

 

Please, excuse my limited English and thanks a lot for all great code.

 

Thanks!!!

 



#40 Amit Shah

Amit Shah

    grocery CRUD Master

  • Advanced Member
  • PipPipPip
  • 1,192 posts
  • LocationMumbai, India

Posted 12 May 2014 - 01:11 PM

well if i am not mistakened by my understanding - it should be the other way around

 

set_relation_dependency('prod_id_subcat', 'prod_id_cat', 'subcat_id_cat');

 

cuz u want the sub category to be visible when the product category is selected. Do try this 1 out... it should work







0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users