AJAX requery on Add/Edit form
- Single Page
Posted 04 November 2012 - 12:36 PM
Table sales has a field [b]group_product[/b](explained just under).
I also have two more tables, [b]products[/b] and [b]groups[/b] of products.
Table [b]products [/b]has a field [b]group_product[/b] that via set_relation gets a value from [b]groups[/b][b]([/b]hence each product belongs to one group).
When I add(or edit) a new sale and I choose the product [b]group[/b](from a list of groups)[b] [/b]I want to requery the field of [b]products[/b] so it displays ONLY the products that belong to this specific group, on the fly(via AJAX).
Any ideas how this can be done?
I tried using callback but the callback doesn't allow to ajaxify the queries!
Posted 16 November 2012 - 08:35 AM
I hope somebody knows the answer and responds since it seems no one has posted anything all this time.
I post my function for your reference, under assets/grocery_crud/themes/datatables/js/datatables-add.js
$('#field-activities_id_chzn').click(function(){
$.ajax({
url: my_url,
dataType: 'json',
success: function(data) {
var select_text, select, option, ul;
select = document.getElementById('field-groups_id');
select.options.length = 0;
select.options.add(new Option());
ul = $('#field-groups_id_chzn ul');
ul.children().remove();
for (var x = 0; x < data.length; x++) {
var day, hour, description, y;
select_text = '';
y = 0;
if(data[x].day == null) day = ' '; else day = data[x].day;
if(data[x].hour == null) hour = ' '; else hour = data[x].hour;
if(data[x].description == null) description = ' '; else description = data[x].description;
select_text = day + ' ' + hour + ' ' + description;
select.options.add(new Option(select_text,data[x].id));
y = x + 1;
ul.append('<li id="field-groups_id_chzn_o_' + y + '" class="active-result" style="">' + day + ' ' + hour + ' ' + description + '</li>');
$('#field-groups_id').each(function() {$(this).trigger('listz:updated')});
}
}
});
});
Within the forms the jquery plugin chosen is used, to help the creation of the forms
Posted 21 November 2012 - 08:42 AM
P.S. I'm busy today, sorry.