Jump to content

Stratos Provatopoulos

Member Since 07 Apr 2013
Offline Last Active Feb 11 2014 04:01 PM

#8708 Edit extra fields in n_n_relations

Posted Stratos Provatopoulos on 31 July 2013 - 07:00 AM

Hello ludwigbernard


My GC version is 1.3.

The error that you are getting is that there is no jQuery so you can simply include it yourself in the header of your file.


I am sorry that I have yet to submit my code as a proper extension, but I have been really swamped and I don't think that I will be able to in the foreseeable future

#6728 Edit extra fields in n_n_relations

Posted Stratos Provatopoulos on 07 April 2013 - 02:16 PM

Hello everybody,
So I am super excited about this library but I was really disappointed that it couldn't handle extra fields in n_n relations.
I decided to program this functionality and now I am sharing the results with you.
In order to use the extra fields functinality you need to pass one extra parameter to the set_relation_n_n function indicating that you want to edit the extra fields 


$crud->set_relation_n_n('actors', 'film_actor', 'actors', 'film_id', 'actor_id', 'name',null, null, TRUE);


You can also indicate that you don't want to edit one of the extra fields of the relation table by using the unset_edit_fields. You will however be required to prepend the name of the field you wish to exclude, with the string extra_field in order to avoid name conflicts








By using the extra option a dropdown box will appear in your edit form that is populated from the selection_table (actors in the site example).
Each time you select one of the values in the dropdown a new tab will appear underneath that contans all the extra fields that are dynamically queried from the relation_table. If the tab already exists it makes that tab active.
The data types work as well but only for int, text, boolean, set, enum, date and datetime. No upload file (although I wanted to it proved hard and I am kinda tired for now) and no relations. 
I believe that if there are extra 1-n or n-n relations in the relation table it deserves to get a separate editing enviroment plus the complexity was simply too much for me.
That is pretty much it 
I am documenting the changes so if anyone is interested please check out my code
In the clear form I needed to trigger the change event of the <select> element
IMPORTANT! The changes currently work ONLY with the datatables theme. It shouldn't be hard however to make it happen for other themes as well
New file to handle the client-side tab initialization functionality 
I needed to add the tabs widget to the jQuery UI custom build. 
Added a few classes for the tabs
Lots and lots of changes to support the new functionality. The changes (hopefully) will not interfere with the rest of the code
Most of the additions where here and some of the new lines of code are kind of ugly to read. If anyone is interested, this file could use some refactoring although I think that it should be done by someone who really understands and knows the rest of the code in order to make full use of it 
Added a couple of functions and modified the function that saved n_n relations and their data
I had to put the config file in global scope in order to call it later on from my code. (There should be a better way to do this)
IMPORTANT! The changes currently work ONLY with tinymce. It should be refactored to work with any editor or at least not die.
I had a strange bug where some of the uniform radio buttons got a display:none so this is pretty much a lousy hack to prevent this by doing .radio{display:inline-block !important}

Attached Files

  • Attached File  tabs.zip   100.76K   995 downloads