⚠ 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

[ANSWERED] set_relation and "Add New" button to quick insert.



Fmasterous

Fmasterous
  • profile picture
  • Member

Posted 14 January 2015 - 12:40 PM

Question: Is there any way to update the dropdown immediatedly after inserting the new data ? Because I need to reload the browser to get the dropdown updated..


Fmasterous

Fmasterous
  • profile picture
  • Member

Posted 14 January 2015 - 12:59 PM

Question: Is there any way to update the dropdown immediatedly after inserting the new data ? Because I need to reload the browser to get the dropdown updated..

 

Thanks for the nice idea. I have one problem. I want the value entered in the New Window to come to the input box of 1st window whenever the submit button of New window is clicked.
How can I do this thing? Please advice

Did you manage to do that ? I want my program to do the same thing...


Fmasterous

Fmasterous
  • profile picture
  • Member

Posted 13 March 2015 - 14:30 PM

Hello guys,

 

First of all, thank you for this nice framework..

 

I've been following this thread and managed to add the fancybox button, but I want it to be only inside the "add/edit" pages, and I want to hide it on the "read" pages...

 

Is there any way to do it without ruining the other functionalities on the "add/edit" pages..

 

Thank you in advance


ljegou

ljegou
  • profile picture
  • Member

Posted 24 August 2015 - 13:48 PM

Hello, just an addendum to this thread to thanks the authors and to point a bug : at the end of the quick_add_save() function in the controller, one should echo the new id value instead of returning it :

			$this->db->insert('country', $data);
			$newid = (string)$this->db->insert_id();
			echo $newid;

rodrigoselau

rodrigoselau
  • profile picture
  • Member

Posted 30 September 2016 - 14:28 PM

I am having difficulty in this code, it sends the information to the "quick_add_ssid_save", only it is not added to the information in the database, the following code:

function quick_add_ssid()
	{

		$javascript = '
			<script>
			function do_quick_ssid_add()
			{
			var ssid_text = $(\'#ssid_nome\').val();
			var ssid_crip = $(\'#ssid_crip\').val();

			$.post(\''.site_url().'/admin/ptp1610/index/quick_add_ssid_save/\', { ssid_nome: ssid_text, ssid_crip: ssid_crip }, function(data) {
				$(\'#ssid_message\').html(\'Successfully inserted a new category\');
			});
			}
			</script>
			';

		$html = '
			<div style="width: 400px; height: 250px;">
			<div style="padding: 5px;">Novo SSID:</div>
			<div style="padding: 5px;"><input type="text" name="ssid_nome" id="ssid_nome"></div>
			<div style="padding: 5px;">Nova Criptografia:</div>
			<div style="padding: 5px;"><input type="text" name="ssid_crip" id="ssid_crip"></div>
			<div style="padding: 5px;"><input type="button" value="Add &raquo;" onclick="do_quick_ssid_add();"> <span id="ssid_message"></span></div>
			</div>
			';

		echo $javascript.$html;
		exit;
	}

		function quick_add_ssid_save()
		{
			//POST ITEMS //only needed if adding a sub category, can get parent ID
			$ssid_nome = $this->input->post('ssid_nome', true);
			$ssid_crip = $this->input->post('ssid_crip', true);
			$data = array(
        		'idSsid_crip' => NULL,
        		'ssid' => 'ssid_nome',
        		'crip' => 'ssid_crip'
			);

			$this->db->insert('csm_Ssid_crip', $data);
	}

Thank you very much in advance

:D


dmanolias

dmanolias
  • profile picture
  • Member

Posted 11 November 2020 - 12:29 PM

Aloha!! biggrin.png

K well I think I know what you might want - so might have a solution for you. I quickly helped some other guys with a fancybox question, here's how you can do something similar:

1. Download Fancybox: http://fancyapps.com/fancybox/

2. Add this code to the view file (You'll have to change a few of the paths and names etc)
 


<link rel="stylesheet" href="<?=base_url()?>assets/plugins/fancybox/jquery.fancybox.css?v=2.0.6" type="text/css" media="screen" />
<script type="text/javascript" src="<?=base_url()?>assets/plugins/fancybox/jquery.fancybox.pack.js?v=2.0.6"></script>
<script type="text/javascript">
$(document).ready(function() {
$(".various").fancybox();

//ADD IN A BUTTON TO ADD TO DROPDOWN
$('#countryID_input_box').append('<a href="<?=site_url()?>/examples/quick_add/" class="various fancybox.ajax">Add</a>');
});
</script>
3. Add this code to you controller (Again you will have to make modifications to work with your own code)


function quick_add()
{
  //EDIT BELOW TO ADD YOU SELECT NAME VALUE
  $args = array(
'category_name' => 'select[name="countryID"]'
  );

  $javascript = '
  <script>
  function do_quick_add()
  {
var category_text = $(\'#category_item\').val();
var category_id = $(\''.$args['category_name'].'\').val();

$.post(\''.site_url().'/examples/quick_add_save/\', { categoryID: category_id, category_item: category_text }, function(data) {
//PREPEND DATA TO SELECT BOX
$(\''.$args['category_name'].'\').prepend(\'<option value="\'+data+\'">\'+category_text+\'</option>\');
//REBUILD SELECT BOX
$(\''.$args['category_name'].'\').trigger("liszt:updated");
//DISPLAY SUCCESS MESSAGE
$(\'#category_message\').html(\'Successfully inserted a new category\');
});
  }
  </script>
  ';

  $html = '
  <div style="width: 400px; height: 250px;">
  <div style="padding: 5px;">New Category Name:</div>
  <div style="padding: 5px;"><input type="text" name="category_item" id="category_item"></div>
  <div style="padding: 5px;"><input type="button" value="Add &raquo;" onclick="do_quick_add();"> <span id="category_message"></span></div>
  </div>
  ';

  echo $javascript.$html;
  exit;
}

function quick_add_save()
{
//POST ITEMS
$categoryID = $this->input->post('categoryID', true); //only needed if adding a sub category, can get parent ID
$category_text = $this->input->post('category_item', true);

//SAVE TO DATABASE
$data = array(
'country_title' => $category_text
);
$this->db->insert('country', $data);

return $this->db->insert_id();
}
VOILA!!!! smile.png

attachicon.gifAdd to select.PNG

Now you can quickly add to dropdowns without having to leave the page.

If it's not exactly what you want you can use a similar approach by using jquery to modify things...

 

 

 

 

is this still working? or is there any other solution? Thanks in advance