⚠ 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 forum is read-only and soon will be archived. ⚠


dmanolias's Content

There have been 5 items by dmanolias (Search limited from 05-December 21)


By content type

See this member's

Sort by                Order  

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

Posted by dmanolias on 11 November 2020 - 12:29 PM in How to and FAQs

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




#152463 Set Relation (dropdown to show only available products)

Posted by dmanolias on 21 November 2020 - 07:04 PM in Grocery CRUD Enterprise

Hi marceloje,

 

Thanks for your answer! It was quite helpful. :)




#152461 Set Relation (dropdown to show only available products)

Posted by dmanolias on 19 November 2020 - 06:04 PM in Grocery CRUD Enterprise

Hey guys! I am using Grocery Crud Enterprise with Code igniter 3.

 

I have two Tables. 

Table 1= Rentals (Rental_id, Product_id, Rental_type, Start_Date, End_Date)

Table 2= Products (Product_id, Product_name)

 

I am using  $crud->setRelation('product_id','products','product_name'); so where I add a new rental there is a dropdown, so I can choose a product.

 

My problem is that I would like to find a way, to be able to see only the "available" products in this dropdown.

 

I have created a view= Available_Products, where I can see in a third table only the available products.

 

Where I use 

$crud->setRelation('product_id','available_products','product_name');

$crud->setprimarykey('product_id','available_products');

 

I can see all the rentals in the table, and only the available products in the dropdown list, but when I click +Add Rental, there is an error. (Maybe because it is a view, and not a table)

 

 

is there a way to fix it? or an other way to make it work?

 

Thanks in advance, please save me ! :)

 

 

 

 




#152449 "Add new" in dropdown list (Set Relation)

Posted by dmanolias on 11 November 2020 - 05:29 PM in I have a question

Hey everyone,

 

First of all, I want to mention that I am a beginner, trying to figure out some things to make my own project for my small business. I am using Grocery Crud Enterprise with Codeigniter 3.

 

So, my question is whether there is an easy way to add a function, so you can add a new record to a dropdown list without going to the secondary table.

 

EXAMPLE:

 

I have two tables. Income and Type. There is a foreign key between those two tables in the column Type_id.

 

When I add a new Income, I search the Type_id in the dropdown list. If there is not the type that I want, I would like to add a new type, which will be saved in the Type Table as well, without having to visit the Type Table at all.

 

By using a "Add new" button in the dropdown list.

 

P.S. I know that this thread exists (http://www.grocerycr...sert/#entry1458), but because I am a beginner I cannot really make it work)

 

P.S.2   It would be REALLY HELPFUL, if you could help me add this function to my project, by recommending a new way to do it, or by helping me find which paths and names I have to change from the #4 post of the thread that I attached above)

 

 

Thanks in advance! Please help  :)




#152448 "Add new" in dropdown list (Set Relation)

Posted by dmanolias on 11 November 2020 - 05:29 PM in I have a question

see below