Urgent: Please help me with repeatable template fields using form builder

edited April 2015 in Modules
Thanks in advance.

I have two tables master (org) and child(team). I am using a form builder to generate form for master tables fields and child tables repeatable fields using template.

There are two issues:
Question 1. My problem is when it comes to edit the record all the repeatable template fields (name,profile picture etc) should be populated (from the table) there in edit mode, how can we achiever this?

Please check the following links for UI
http://lokeshgupta.in/1fuel.PNG


Here is the snippet

function edit($id) {
$this->load->library('form_builder');
$this->load->model('teams_model');
$data['profile_section'] = $this->org_model->find_one_array(array('member_id' => $id));
$vars['team'] = $this->teams_model->find_all(array('member_id' => $id));
// load the custom form fields
$this->form_builder->load_custom_fields(APPPATH.'config/custom_fields.php');
$fields1 = $this->org_model->form_fields();
$fields['profile_section'] = array(
'display_label' => TRUE,
'type' => 'template',
'label' => 'Profile section',
'fields' => $fields1,
'add_extra' => FALSE,
'repeatable' => FALSE,
'removeable' => FALSE,
'style' => 'width:100%'
);
$fields['team_members'] = array(
'display_label' => TRUE,
'type' => 'template',
'label' => 'Team Members',
'max' => 10,
'depth' => 10,
/*'init_display' => 'none',*/
'fields' => array(
'image' => array('type' => 'asset','create_thumb' => TRUE,'maintain_ratio' => TRUE, 'multiple' => FALSE, 'readonly' => 'readonly','required' => TRUE,'hide_image_options' => FALSE,'folder' => '/bdn/','subfolder' => 'team'),
'team_member_name' => array('type' => 'textbox','label' => 'Name','required' => TRUE),
'team_member_id' => array('type' => 'hidden','style' => 'display:none')
),
'init_display' => FALSE ,
'add_extra' => TRUE,
'repeatable' => TRUE
);

foreach($fields as $sectionKey => $fieldsVal)
{
foreach($fieldsVal['fields'] as $key => $val)
{
if(isset($data[$sectionKey][$key])){
$fields[$sectionKey]['fields'][$key]['value'] = $data[$sectionKey][$key];
}
}
}
if(isset($_POST['Submit'])){
//save operation
}
$this->form_builder->set_fields($fields);
// render the page
$vars['form'] = $this->form_builder->render();
$vars['page_title'] = $this->fuel->admin->page_title(array(lang('module_membership')), FALSE);
$crumbs = array('tools' => 'Partners', 'Edit');
$this->fuel->admin->set_titlebar($crumbs, 'ico_membership');
$this->fuel->admin->render('_admin/edit', $vars, '', MY_FOLDER);
}


Question 2. I tried using jquery but still it only creates two template fields. I read in documentation that depth property decided this and it's upper limit is 2 only.


$(document).ready(function(){


<?php foreach($team as $index=>$tm){ ?>
alert('<?php echo $tm->profile_image;?>');
$(".add_another").eq(<?php echo $index;?>).trigger('click');
$("input[name='team_members["+<?php echo $index;?>+"][image]']").val("<?php echo $tm->profile_image;?>");
$("input[name='team_members["+<?php echo $index;?>+"][team_member_name]']").val("<?php echo $tm->name;?>");
$("input[name='team_members["+<?php echo $index;?>+"][team_member_id]']").val("<?php echo $tm->id;?>");
<?php } ?>
});

Comments

  • edited 1:57AM
    I have resolved second issue related to jquery. Silly mistake acutally

    $(".add_another").trigger('click'); instead $(".add_another").eq(<?php echo $index;?>).trigger('click');

    :)
  • edited 1:57AM
    To populate the values of the repeated fields, you should set the value as an array or JSON string in the format of an array of array values like so:
    $value = array( array('image' => 'image1.jpg', 'name' =>'Name 1'), array('image' => 'image2.jpg', 'name' =>'Name 2'), );
Sign In or Register to comment.