How is it possible to do this?
tnx.
⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠
Posted 18 June 2014 - 12:55 PM
How is it possible to do this?
tnx.
Posted 19 June 2014 - 16:11 PM
In class Grocery_CRUD .. add the following
//Add the variable for form button protected $form_buttons = array();
......
/** * * Allows user to add extra button to the add / edit form * @param string $field * @param string $mask */ public function form_buttons($button , $js_call, $class=null) { $this->form_buttons[$button] = array('js_call'=>$js_call, 'class'=>$class); return $this; }
.....in the function showAddForm ....... add the following
$data->buttons = $this->form_buttons;
now in add.php in whtever template you use... ..... after all the buttons rendering code is done with ... add the follwing
<?php } if(isset($buttons) && is_array($buttons) && count($buttons) > 0) { $n=1; foreach ($buttons as $formName => $frmConfig) { if(array_key_exists('class', $frmConfig)) { $class = $frmConfig['class']; } else { $class = 'btn btn-large'; } ?> <div class='form-button-box'> <input class='<?php echo $class?>' type='button' onclick="<?php echo 'javascript:' . $frmConfig['js_call'] . '()'?>" value='<?php echo $formName; ?>' id="user-button_<?php echo $n?>" /> </div> <?php } } ?>
once this is done .. now how to add the same in the controller ...
//Add extra form buttons $crud->form_buttons('Add Another Location','add_and_edit', 'btn btn-success btn-large');
now remember ... the 1st parameter is the title of the button, the second param is the javascript call ... and the 3rd parameter is the css code for styling
so now in javascript. The concept here is that you have to first make the form to be submitted. So submit the same. Once the ajax call is over, since we need to redirect, we will move to the edit url.
function add_and_edit() { btn_add_edit_pressed = true; $('#crudForm').trigger('submit'); } $(document).ready(function() { $(".go-to-edit-form:visible").livequery(function() { if (btn_add_edit_pressed) { btn_add_edit_pressed = false; } else { return; } console.log("Yes i got in visible here") url = $(".go-to-edit-form").attr('href'); console.log("Changing location to " + url); window.location.assign(url); }) });
Crude.... long but this is the only way to go on with where you control the actions !! Other way is directly modify the add.php in the template and create the code for extra button.