⚠ 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. ⚠

  •     

profile picture

Load dynamic js and css in output view of grocery crud add/edit form



aniruddh
  • profile picture
  • Member

Posted 06 October 2015 - 06:42 AM

Below is my controller code:
 
class user extends CI_Controller {
public function __construct() {
parent::__construct ();
 
$this->load->database ();
$this->load->helper ( 'url' );
 
$this->load->library ( 'grocery_CRUD' );
 
}
 
// View rendering function.
public function _example_output($output = null, $usertype = null) {
$this->load->view ( 'header', $output );
$this->load->view ( 'mainview', $output );
$this->load->view ( 'footer' );
}
 
// Main function, which displays list.
public function listuser() {
$user_type = $this->session->userdata ( 'usertype' );
 
try {
$crud = new grocery_CRUD ();
 
$crud->set_theme ( 'datatables' );
$crud->set_table ( 'user' );
$crud->set_subject ( 'Supplier' );
$crud->columns ( 'name', 'email', 'contact', 'location' );
$crud->where ( 'user_type', 'supplier' );
$crud->order_by ( "user_id", "desc" );
$crud->edit_fields ( 'group_id', 'name', 'email', 'contact', 'location', 'status' );
$crud->add_fields ( 'username', 'password', 'supplier_number', 'group_id', 'name', 'email', 'contact', 'location', 'user_type', 'status' );
 
 
$crud->required_fields ( 'group_id','name', 'email', 'contact', 'location', 'status' );
 
$crud->callback_add_field ( "supplier_number", array (
$this,
"add_supplier_number"
) );
 
$this->load->model ( "user_group" );
$group = $this->user_group->get_user_group ();
 
foreach ( $group as $key => $value ) {
$group_dropdown [$value ['group_id']] = $value ['group_name'];
}
$crud->field_type("group_id", "dropdown",$group_dropdown);
$crud->display_as('group_id','Group Name');
 
// Making field hidden to post value.
//$crud->field_type ( "group_id", "hidden" );
$crud->field_type ( "username", "hidden" );
$crud->field_type ( "password", "hidden" );
$crud->field_type ( "user_type", "hidden", "supplier" );
 
// removing view option from record.
$crud->unset_read ();
//$crud->unset_export ();
$crud->unset_print ();
 
// Custom update function.
$crud->callback_before_insert ( array (
$this,
'add_user'
) );
 
// Custom Email Sending function.
$crud->callback_after_insert ( array (
$this,
'send_email_supplier'
) );
 
//$crud->limit(1);
// $crud->callback_column("s")
$output = $crud->render ();
echo "<pre>";
print_r($output);exit;
$is_admin = false;
 
if ($user_type === "admin") {
$is_admin = true;
}
 
$output->is_admin = $is_admin;
// $usertype ['is_admin'] = $is_admin;
 
$this->_example_output ( $output );
} catch ( Exception $e ) {
show_error ( $e->getMessage () . ' --- ' . $e->getTraceAsString () );
}
}

 

 Now i want to create client side validation for add/edit form in grocery crud.

I want to load jquery.validation.js & dynamic js file for each form i.e. adduser.js in user add/edit form to validate the form using jquery validation plugin.

 

I have below code in header.php :

 

<?php
if (isset ( $css_files )) :
foreach ( $css_files as $file ) :
?>
<link type="text/css" rel="stylesheet" href="<?php echo $file; ?>" />
<?php endforeach;  endif; ?>
<?php
 
if (isset ( $js_files )) :
foreach ( $js_files as $file ) :
?>
<script src="<?php echo $file; ?>" type="text/javascript"></script>
<?php endforeach;  endif;?>
</head>

 

 

Now how to load dynamic js & css files from controller to output function and load jss & css in add/edit form of grocery crud.

 

Appreciate quick reply & help.