Sap
Sap

Reputation: 5291

Grails one to many relationship view

I have two grails domain classes

 Class MultipleChoiceQuestion {
    String question
    static constraints = {
        ...
    }
    static hasMany = [options:MultipleChoiceOption]
   }

and

class MultipleChoiceOption{
    String answerOption
    boolean correctOption
    MultipleChoiceQuestion question
    static constraints = {
        ...
    }
}

I want my users to be able to create a question then add atleast 3 options without navigating/clicking on different screens.

My first question is must I generate view and start editing code?

And if the answer to question above is yes then my second question is, what's the best way to save a question along with multiple options in one form submit? The generated code will have something like following for each option.

<g:textField name="answerOption" value="${answerOptionInstance?.answerOption}"/>
<g:checkBox name="correctOption" value="${answerOptionInstance?.correctOption}"/>

how can I have multiple such elements in one page? Please see the wireframe to get an idea of what I want to achieve, my apologies for poorly created wire frame. Click on the link for opening the image in your browser http://cynosuredev.com/wf.png Wireframe

Upvotes: 0

Views: 3570

Answers (1)

You don't have to use Grails scaffolding if you don't want to. Since this is a pretty specialized form, you should construct the HTML yourself. I've created a test project at github that shows a good design for this problem. Check it out.

Upvotes: 0

Related Questions