Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

need help on editing nested-forms #204

Closed
Ezekiah opened this issue Mar 17, 2014 · 4 comments
Closed

need help on editing nested-forms #204

Ezekiah opened this issue Mar 17, 2014 · 4 comments

Comments

@Ezekiah
Copy link

Ezekiah commented Mar 17, 2014

Hello,

My aim is to be able to call existing nested objects in my database and edit them.
To do so I created a template which display the form objects according to an xml schema, each class has it's own form.

Example of form :

builder = Nokogiri::XML::Builder.new do |t|
t.agent{      
          t.association(:type=>'association', :name=>'orgunits',  :display=>'public', :class_name=>'Orgunit')
          t.association(:type=>'association', :name=>'persons',  :display=>'public', :class_name=>'Person')
          t.rec_class(:type=>'hidden', :value=>'Agent')
          t.rec_id(:type=>'hidden', :value=>'', :display=>'public')

       }

I can display existing objects with the link_to_add like this :

- link = link_to_add_association(' ', f, node_name.to_sym, :partial=>'/studies/display_fields', 
                  :render_options => {:locals => {:fedora_object=>data, :rec_type=>node_name, :edit=>true,:xml=>Object.const_get(class_name.capitalize).xml_form.to_xml,  :xpath=>'/'+class_name.to_s.singularize.downcase+'/*'}, },:data => {"association-insertion-method" => "before" },)
                  - link = Nokogiri::HTML(link)

However when I open my edit popup the link_to add buttons generate wrong names.

It should output :
study[authors_attributes][1395055572220][orgunits_attributes][1395055573891][name]

But it displays :
study[new_authors][orgunits_attributes][1395055573891][name]

Could you help me, I don't think you have time to explore my code but do you know a good way to edit nested forms ?

My github is here : https://github.com/Ezekiah/hydra-head-archipolis/blob/master/app/views/studies/_display_fields.html.haml

@Ezekiah Ezekiah changed the title Call js script on existing inputs need help on editing nested-forms Mar 17, 2014
@nathanvda
Copy link
Owner

I quickly checked your link, and you have an awful lot of code in a partial. Commonly it is not good practice to be having that much code in a view.

Also it is not entirely clear what you are doing exactly.

So, this gem is intended to be used with the form_for and fields_for helpers (and their derivatives in simple_form or formtastic). So not sure how you build your form, with XMLBuilder --> are you building your html that way?

It is a technique I do not know and I am not sure cocoon supports this at all.

Anyway: a quick look revealed you use simple_form_for, but there is no simple_fields_for call anywhere, this explains why the attributes are built incorrectly. But frankly I do not understand your code well enough to give you a good solution at this moment.
You seem to be using the same view to be iterating over all elements, and to render a single element.

@Ezekiah
Copy link
Author

Ezekiah commented Mar 17, 2014

Yes this is quiet hard to understand

On Mon, Mar 17, 2014 at 2:48 PM, Nathan Van der Auwera <
notifications@github.com> wrote:

I quickly checked your link, and you have an awful lot of code in a
partial. Commonly it is not good practice to be having that much code in a
view.

Also it is not entirely clear what you are doing exactly.

So, this gem is intended to be used with the form_for and fields_forhelpers (and their derivatives in
simple_form or formtastic). So not sure how you build your form, with
XMLBuilder --> are you building your html that way?

It is a technique I do not know and I am not sure cocoon supports this at
all.

Anyway: a quick look revealed you use simple_form_for, but there is no
simple_fields_for call anywhere, this explains why the attributes are
built incorrectly. But frankly I do not understand your code well enough to
give you a good solution at this moment.

Reply to this email directly or view it on GitHubhttps://github.com//issues/204#issuecomment-37816546
.

Alexandre Aazzouz-Leconte

Développeur web

http://alexandre-leconte.fr

@nathanvda
Copy link
Owner

Ok, but you are most definitely missing the simple_fields_for, so you should try to fix that. And if you would be able to make it a little more simpler, your code, it will become easier for you and me to to understand and help you. But of course, it could be that it needs to be this complicated.

Good luck 👍

I am not sure if I can do a lot to help you now?

@nathanvda
Copy link
Owner

Closed due to inactivity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants