Welcome Guest, Not a member yet? Register   Sign In
Adding dropdown to modal (ISSUE)
#1
Sad 

Hello,

It is a first time I'm using CodeIgniter and wanted to add a simple feature as drop down which works as auto-fill of information straight from DB.
Visually everything looks alright after adding a simple code, but it immediately made "Submit" button to not work, i mean that it just closes modal and no information is saved...

These are the codes that I added to view file:

Code:
<div class="form-group filled">

    <label for="item_id"><?=$this->lang->line('application_item');?></label>
    <select name="item_id" style="width: 100%;" id="itemChange"  class="chosen-select">

      <option value="0">-</option>
    <?php  foreach ($items as $value){ ?>
<option value="<?php echo $value->id; ?>" data-nm="<?php echo $value->name; ?>" data-val="<?php echo $value->value; ?>" data-desc="<?php echo $value->description; ?>"><?php echo $value->name." - ".$value->value." ".$core_settings->currency; ?></option>
    <?php }  ?>
</select>

</div>




<script>$("#itemChange").on("change", function () {var nm = $(this).find(':selected').data('nm');var val = $(this).find(':selected').data('val');
     var desc = $(this).find(':selected').data('desc');$("#name").val(nm); $("#value").val(val); $(".desc").val(desc);});   
     </script>



This is a view file:
Code:
<?php
$attributes = array('class' => 'dynamic-form', 'data-reload' => 'task-list', 'data-reload2' => 'milestones-list', 'data-reload3' => 'taskviewer-content', 'data-baseurl' => base_url(), 'id' => '_task');
echo form_open($form_action, $attributes);
$public = "0";
?>

<?php if(isset($task)){ $public = $task->public; ?>
  <input id="id" type="hidden" name="id" value="<?php echo $task->id; ?>" />
<?php } ?>
<div class="form-group">
        <label for="name"><?=$this->lang->line('application_task_name');?> *</label>
        <input id="name" type="text" name="name" class="form-control resetvalue" value="<?php if(isset($task)){echo $task->name;} ?>"  required/>
</div>
<div class="row">
    <div class="col-md-6">
         <div class="form-group">
                <label for="priority"><?=$this->lang->line('application_priority');?></label>
                <?php $prioritys = array();
                        $prioritys['0'] = '-';
                        $prioritys['1'] = $this->lang->line('application_low_priority');
                        $prioritys['2'] = $this->lang->line('application_med_priority');
                        $prioritys['3'] = $this->lang->line('application_high_priority');
                if(isset($task)){$priority = $task->priority;}else{$priority = "2";}
                echo form_dropdown('priority', $prioritys, $priority, 'style="width:100%" class="chosen-select"');?>
        </div>
    </div>


    <div class="col-md-6">
         <div class="form-group">
                <label for="status"><?=$this->lang->line('application_status');?></label>
                <?php $options = array(
                          'open'  => $this->lang->line('application_open'),
                          'done'    => $this->lang->line('application_done'),
                        );
                        $status = FALSE;
                        if(isset($task)){ $status = $task->status;}
                        echo form_dropdown('status', $options, $status, 'style="width:100%" class="chosen-select"'); ?>
        </div>
    </div>
</div>

<div class="form-group filled">

    <label for="item_id"><?=$this->lang->line('application_item');?></label>
    <select name="item_id" style="width: 100%;" id="itemChange"  class="chosen-select">

      <option value="0">-</option>
    <?php  foreach ($items as $value){ ?>
<option value="<?php echo $value->id; ?>" data-nm="<?php echo $value->name; ?>" data-val="<?php echo $value->value; ?>" data-desc="<?php echo $value->description; ?>"><?php echo $value->name." - ".$value->value." ".$core_settings->currency; ?></option>
    <?php }  ?>
</select>

</div>



<div class="form-group">
        <label for="user"><?=$this->lang->line('application_assign_to_agent');?></label>
        <?php $users = array();
                $users['0'] = '-';
                 foreach ($project->project_has_workers as $workers):
                    $users[$workers->user_id] = $workers->user->firstname.' '.$workers->user->lastname;
                endforeach;
        if(isset($task)){$user = $task->user_id;}else{$user = $this->user->id;}
        echo form_dropdown('user_id', $users, $user, 'style="width:100%" class="chosen-select"');?>
</div>

<?php if($project->company_id != 0){?>
<div class="form-group">
        <label for="client"><?=$this->lang->line('application_assign_to_client');?></label>
        <?php $clients = array();
                $clients['0'] = '-';
                 foreach ($project->company->clients as $workers):
                    $clients[$workers->id] = $workers->firstname.' '.$workers->lastname;
                endforeach;
        if(isset($task)){$client = $task->client_id;}else{$client = 0;}
        echo form_dropdown('client_id', $clients, $client, 'style="width:100%" class="chosen-select"');?>
</div>

<?php } ?>

<div class="form-group">
        <label for="value"><?=$this->lang->line('application_value');?></label>
        <input id="value" type="text" name="value" class="form-control decimal" value="<?php if(isset($task)){echo $task->value;} ?>" />
</div>
<div class="row">
    <div class="col-md-6">
            <div class="form-group">
                                      <label for="start_date"><?=$this->lang->line('application_start_date');?></label>
                                      <input class="form-control datepicker not-required" name="start_date" id="start_date" type="text" value="<?php if(isset($task)){ echo $task->start_date;} ?>" />
            </div>
    </div>
    <div class="col-md-6">
            <div class="form-group">
                                      <label for="due_date"><?=$this->lang->line('application_due_date');?></label>
                                      <input class="form-control datepicker-linked not-required" name="due_date" id="due_date" type="text" value="<?php if(isset($task)){echo $task->due_date;} ?>" />
            </div>
    </div>
</div>
<div class="form-group">
                        <label for="textfield"><?=$this->lang->line('application_description');?></label>
                        <textarea class="form-control desc" id="textfield" name="description"><?php if(isset($task)){echo $task->description;} ?></textarea>
</div>

<div class="form-group">
<label for="textfield"><?=$this->lang->line('application_visibility');?></label>
<ul class="accesslist">

                        <li>
                        <input name="public" class="checkbox" data-labelauty="<?=$this->lang->line('application_task_public');?>" value="1" type="checkbox" <?php if($public == "1"){ ?> checked="checked" <?php } ?> />
                        </li>
</ul>
</div>

        <div class="modal-footer">
          <?php if(isset($task) && !isset($nondeletable)){ ?>
            <a href="<?=base_url()?>projects/tasks/<?=$task->project_id;?>/delete/<?=$task->id;?>" class="btn btn-danger pull-left button-loader" ><?=$this->lang->line('application_delete');?></a>
          <?php }else{  ?>
                <a class="btn btn-default pull-left" data-dismiss="modal"><?=$this->lang->line('application_close');?></a>
          <?php if (!isset($nondeletable)) { ?>
        <i class="icon dripicons-loading spin-it" id="showloader" style="display:none"></i>
        <button id="send" name="send" data-keepModal="true" class="btn btn-primary send button-loader"><?=$this->lang->line('application_save_and_add');?></button>
          <?php } ?>
        <?php } ?>
        <button name="send" class="btn btn-primary send button-loader"><?=$this->lang->line('application_save');?></button>
        </div>
<?php echo form_close(); ?>
<script>$("#itemChange").on("change", function () {var nm = $(this).find(':selected').data('nm');var val = $(this).find(':selected').data('val');
     var desc = $(this).find(':selected').data('desc');$("#name").val(nm); $("#value").val(val); $(".desc").val(desc);});   
     </script>


And this is the code that I used for controller:

Code:
$this->view_data['items'] = Item::find('all', ['conditions' => ['inactive=?', '0']]);


In modal everything visually works as it should be, data is displayed and autofill is working, but it just stops saving any data...
And one more thing that I noticed, that modal stops working in case I add any code, for ex. if I remove code from view it is still not working, or if I remove code from controller but keep in view, it is still not working... But if I remove from both files, everything becomes functional...


Attaching also the code of controller in attachments....


Please, if someone could help me, maybe that's a small issue or maybe it needs a bigger changes, in any way, I can pay something just to get it working, as it is critical for me  Huh
Reply
#2

Found out, that it creates entries in Database, but it just for unknown reason keeps project_id as NULL, that's why the information is not shown
Reply
#3

@Lukas.glu,

Are you using a browser tool to see if the results are being properly sent to the processing controller? What messages are you seeing when you try to process data from the form?
Reply




Theme © iAndrew 2016 - Forum software by © MyBB