Note the upgraded forum! If you are experiencing issues logging in, you may need to reset your password which should send an email. If the email doesn't arrive, be sure to check your spam folder just in case.

Trigger ajax call

edited August 2017 in Modules
I have a model with some code in function form_fields:
$fields['cat_id']['order'] = 2;
$fields['cat_id']['label'] = 'Category';
$fields['cat_id']['type'] = 'select';
$fields['cat_id']['options'] = $categories->options_list();
$fields['cat_id']['first_option'] = 'Choose Category..';
$fields['cat_id']['value'] = $category_id;

$fields['sub_cat']['order'] = 3;
$fields['sub_cat']['label'] = 'Sub Category';
$fields['sub_cat']['type'] = 'dependent';
$fields['sub_cat']['depends_on'] = 'cat_id';
$fields['sub_cat']['ajax_data_key_field'] = 'category_id';
$fields['sub_cat']['url'] = fuel_url('pm/pm_sub_categories/ajax/options');
$fields['sub_cat']['multiple'] = FALSE;
$fields['sub_cat']['value'] = $sub_category_id;


How to manually trigger ajax call in field sub_cat with javascript?
I try $("#sub_cat").change() with no success.

Comments

  • edited 6:32PM
    I have to do it manually because if i change option in category, sub_cat_item not change its options.

    Additional code in function form_fields:
    $fields['sub_cat_item']['order'] = 4;
    $fields['sub_cat_item']['label'] = "Sub Category Item";
    $fields['sub_cat_item']['type'] = 'dependent';
    $fields['sub_cat_item']['depends_on'] = 'sub_cat';
    $fields['sub_cat_item']['ajax_data_key_field'] = 'sub_category_id';
    $fields['sub_cat_item']['url'] = fuel_url('pm/pm_sub_category_items/ajax/options');
    $fields['sub_cat_item']['multiple'] = FALSE;
    $fields['sub_cat_item']['value'] = $values['sub_cat_item_id'];
Sign In or Register to comment.