Say I have Author and Book domain classes (one Author has many Books). The user goes to book/create to enter the details for a new Book. One of the fields in the form is a select with all Author instances in the database, but this Book belongs to an Author who is not in the database.
What is the best way to implement the interface to add a new Author in grails, but keep the whole process relatively painless for the user? This is what I am thinking:
- add
Authorfields toBookcreate view in a hidden div - add a link which will show the above mentioned fields and a save button
- post the
Authorfields via Ajax to save them - update the author select to include the newly created
Author - auto select the new
Authorin the select
I will work, but it seems a bit of a nasty approach (hacking the Book create view with non-Book fields). Is there a nicer way?
I don’t think placing non-book fields in Book view is nasty.
What I don’t understand is the need for separate Ajax call to save new Author – why not do this in the same action that the book is created in? If user chose an existing Author, set up the book as usually. If not, retrieve the author field values, create new
Authorinstance, save it and then set book’s author field to it.