⚠ 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

jQuery multiselect sends wrong priority on insert with set_relation_n_n



ricardomduarte

ricardomduarte
  • profile picture
  • Member

Posted 06 March 2013 - 16:39 PM

Hi,

 

First of all, congratulations for the great piece of software that is GroceryCRUD. I love the architecture simplicity and flexibility.

 

I'm having the following problem:

 

 

I'm working on the form to add a musical project.

 

The "project" table has an n-to-n relationship with the "musician" table, materialized on the relationship table "musicianinproject". 

 

On grocery crud I use the following:

 

$crud->set_relation_n_n('musicians', 'musicianinproject', 'musician', 'project_id', 'musician_id', 'name', 'priority');

 

This is working well and if I have a priority manually defined on the database records the musician list is displayed correctly.

 

 

However, when I try to add a project via Grocery Crud, although I am able to select the musicians and order them on the multiselect interface, when I hit Save to submit the form, musicians array on the post array comes with the wrong order, and are thus written to the database with the wrong priority.

 

 

I read through the source code and investigated the issue and the most relevant information I got is on the post below, that relates to the same issue on the jQuery multiselect:

 

http://stackoverflow.com/questions/13243417/jquery-multiselect-selected-data-order?rq=1

 

 

It seems that, since the source of the post data is a <select> element, there is no guarantee about the order of the selected options that will be sent by the browser.

 

 

If necessary I can post the code and logs on the server side showing the post data, but I will probably need to change the code to strip it of extra code irrelevant to this problem.

 

 

Thanks in advance for any help on this,

 


davidoster

davidoster
  • profile picture
  • Member

Posted 07 March 2013 - 22:50 PM

I am not sure what exactly you are having as a result in your database.

Please have a look on this, http://eletter.gr/samples/gc_ic2/index.php/gc_examples/film_management

 

This is the films' example that is included in the stable 1.3.3 version of Grocery CRUD library.

Try it out by adding and then editing the film you stored.

On the fields, Actors and Categories, which are defined via a set_relation_n_n, the order of submission is retained.

 

$crud = new grocery_CRUD();
		
		$crud->set_theme('datatables');
		$crud->set_table('film');
		$crud->set_relation_n_n('actors', 'film_actor', 'actor', 'film_id', 'actor_id', '{fullname} {last_update}','priority');
		$crud->set_relation_n_n('category', 'film_category', 'category', 'film_id', 'category_id', 'name', 'priority');
		$crud->unset_columns('special_features','description','actors');
		
		$crud->fields('title', 'description', 'actors' ,  'category' ,'release_year', 'rental_duration', 'rental_rate', 'length', 'replacement_cost', 'rating', 'special_features');
		
		$output = $crud->render();
		
		$this->_gc_output($output);

 

I hope this is the issue you are referring to and this helps you out.