Jump to content


Robert

Member Since 03 Jun 2013
Offline Last Active Jan 26 2015 06:42 AM
-----

Posts I've Made

In Topic: Chosen dropdown update

22 January 2015 - 02:21 PM

Ok .. so I change :

	public function add()	{
		$tdata = array( 'name' =>  $this->input->post('name') );

		// insert the new record
	        $this->db->insert('table', $tdata); 

		// get the row elements
		$q = $this->db->get_where('table', array('id' => $this->db->insert_id()));
		$data = $q->row();

		// create array and encode with json
		$last_insert = array('id' => $data->id, 'den' => $data->denumire, );
		$json = json_encode($last_insert);
	    
	    return $json;
	}

Dont no if this is the correct way to send the inserted id/name to the view ?

 

 

Then in the view :

            success:function(tdata)   {
                // close the model
                $('#myModal').modal('hide');

                // add the record and refresh
                $(".chosen-select").append("<option value='9999'>A new option!!</option>");
                $('.chosen-select').trigger('liszt:updated');
            }

But how can i decode the json in the view ? 

 

i read i need to do something like 

$obj = json_decode($json);
print $obj->{'id'};

but im stuck on how to change my code .....


In Topic: Chosen dropdown update

21 January 2015 - 12:06 PM

This is the code i have so far ..

 

View :

<script>
    <?php if($state == 'add')  { ?>
        $(document).ready(function() {
            $('#beneficiar_p_display_as_box').append('<a class="btn" id="button" data-toggle="modal" data-target=".bs-example-modal-lg"><i class="icon-plus-sign"></i> Add </a>');
        });
    <?php } ?>
</script>

<div class="modal fade bs-example-modal-lg" tabindex="-1" id="myModal" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
                <h4 id="myLargeModalLabel" class="modal-title">Add</h4>
            </div>
            <div class="modal-body" >
                <form class="sky-form" id="sky-inchidere" method="post" accept-charset="utf-8" action="">
                        <dl class="dl-horizontal" style="min-height:100px">

                            <dt>Name<span class="color-red">*</span></dt>
                            <dd>
                                <section>
                                    <label class="input">
                                        <i class="icon-append fa fa-inbox"></i>
                                        <input type="text" value="" name="name" id="name" required>
                                        <b class="tooltip tooltip-bottom-right">Add</b>
                                    </label>
                                </section>
                            </dd>

                        </dl>
                    <button type="submit" class="btn-u" style="float:right; margin-top:-35px;">Submit</button>
                </form>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
$(document).ready(function(){
    $("#sky-inchidere").submit(function(e)    {
        e.preventDefault();
        var tdata= $("#sky-inchidere").serializeArray();

        $.ajax({
            type: "POST",
            url: 'http://localhost/new/test/add',
            data: tdata, 

            success:function(tdata)   {
                // close the model
                $('#myModal').modal('hide');

                // update dropdownlist ??
                $('.field-beneficiar_p').trigger('chosen:updated');

            },
            error: function (XHR, status, response) {
               alert('fail');
            }
        });
    });
});
</script>

Controller (I added the modal code here for test)  :

    public function add()    {
     $tdata = array( 'name' => $this->input->post('name') );
     $this->db->insert('table', $tdata);
    }

 

All works good except I don't no how to update the dropdownlist with the new item added .... If someone done this any help will be appreciated.

.


In Topic: Chosen dropdown update

21 January 2015 - 10:28 AM

How can I update the options of the list ? all i find was uses of "chosen:updated" and "liszt:updated" ...

 

Is there any way to provide me a small example or a link ?

Thanks for your time.


In Topic: Chosen dropdown update

21 January 2015 - 06:37 AM

I did it in the ajax success

            success:function(tdata)
            {
                // update dropdown ??
                $('.chosen-select').trigger('liszt:updated');
            },

and i tried a loot of different stuff but with no success ... can you provide a example if you have time ?

Thanks for the replay.


In Topic: callback column + array

31 July 2014 - 02:06 PM

Damn that was easy .. if someone gets into this problem to you can use implode :

$test1=implode($test,"<br>");
return $test1;

Thanks a loot 

Amit Shah