⚠ 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

"Add More field" feature on "Add" Page



likhon3k
  • profile picture
  • Member

Posted 09 May 2013 - 17:37 PM

Hello Guys,

I have created a table for one of my projects like My Fevorite subjects as my_feb_subject and I have created three field initial.

 

my_feb_subject

id

first_subject

second_subject

 

 

Now I want to add custom field option like "Add More Subject" on below of "Add" page. If some one wants to like add more subject like third_subject, fourth_subject so on. Then he/she needs to click on "Add More Subject" button to add more field.

 

I search on forum but failed to find the solution.

 

1) Is it possible to include this features on any table page??

 

2) Is it possible to create custom number of table field from Add Page?

 

If any of you have the idea or solution of this problem, please tell me.

 

Thanks in advance

 


davidoster
  • profile picture
  • Member

Posted 09 May 2013 - 20:04 PM

Theoretically it is possible (since we have access to the database, we can ALTER TABLE) but this is not something that you would normally do.

 

Instead, someone would have a two (2) tables database structure where :

 

table main_subject

id, autoincrement

description, text

 

table sub_subjects

id, autoincrement

id_main, FK of main_subject.id

subject, text (or whatever database type you need to have)

 

This is a typical master/detail form though.

In order to be able to insert sub-subjects at least one main subject must exist.

Then the user of the application can see a Grocery CRUD of the table sub_subjects and add as many subjects he needs to.

 

I hope this helps you.


likhon3k
  • profile picture
  • Member

Posted 23 June 2013 - 08:24 AM

Your answer is not clear to me. sorry for delay. I am giving an example. see the below image:

 

 
[sharedmedia=core:attachments:583]

If i need to add more field to more educational degree. i need to click on "Add more" button. If I click on Add more button then another input box open and it will store in database. like this way.

 

How is it possible?


Amit Shah
  • profile picture
  • Member

Posted 26 June 2013 - 15:48 PM

Well you can create your custom javascript to achieve the functionality. You can define the name of the subjects / fields whatever you like while you add. One thing recomended

In this case will be to manage your own patterned insert making use of callback_insert there you can handle the way you plan to manage your inserts of multiple new subjects.


likhon3k
  • profile picture
  • Member

Posted 20 September 2013 - 19:27 PM

After Long time, still I didnt get any proper solution. I think I was unable to clear my problem.

 

I want to create one or more field into database from frontend, if I need.

 

Suppose: I have a table column name my_favorite_subject and I assigned two field for initially. Subject1, Subject2. after Subject2  I want to add a link for add more subject filed like "Add More Subject" like Subject 3. Subject4 and so on.

 

my_favorite_subject:

Subject1:

Subject2:

Add More Subject

 

If some one click on "Add More Subject" then Automatically Subject3 field will be created on frontend and If I put subject name then it will be inserted into subject3 field into database which I was not declare first time. but it will be created after Add More Subject link.

 

I hope I can clear it now. If any one know the solution, please share it.


Amit Shah
  • profile picture
  • Member

Posted 24 September 2013 - 09:48 AM

Well.. this - i will not recommend doing it using grocery crud - why .. simple thing, this anyways is going to be more complex scenario to adjust / alter in grocery crud then simple form

 

Secondly if you want to achieve in the functionality in gc ..

  1. you need custom javascript .. which on click of that button - will on the fly create the field.
  2. You will need to add a field (that dose not exists .with a blank label and a custom callback to that field) .. the callback will be to the JavaScript function defined in the custom js created
  3. Then you need to do a callback_insert - write your own logic for insertion .. and put in the business logic out there

Such complexity if you want to persist to - u can continue with GC for adding in this form.. else u can simply have a work around with the regular code u adhere in CI