Hello Assem, just try open the ajax_grocery_CRUD file and chance $state_code from private to protected in the line 6
Simple dependant dropdown extension
Posted 16 August 2013 - 18:45 PM
Posted 21 August 2013 - 15: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..
Posted 22 August 2013 - 00: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?
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.
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, [member=amit shah].
Posted 27 August 2013 - 17: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
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.
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
Posted 04 September 2013 - 16:00 PM
Hi,
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
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.
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
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....
Posted 08 October 2013 - 15:49 PM
Appreciate if someone can post his/her working example using this ajax_grocery_crud.
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!
Posted 10 November 2013 - 06:13 AM
Hello and welcome to the forums [member=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.
Posted 12 November 2013 - 19: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.
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.
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.
[attachment=794:relation_dependency.jpg]
Please, excuse my limited English and thanks a lot for all great code.
Thanks!!!
Posted 12 May 2014 - 13: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