Question about repeatable input in grails form

M

margafred

Guest
Assuming that i have the following data in my params

Code:
params:[input:[1, 2, 3]]

And i have the following form in my Grails app

Code:
<div class="block1">   
    <label class="control-label">
        <g:message code="input.label" default="Input"/>
    </label>
    <div class="controls">
        <g:textField id="input1" name="input" value="${input}" readonly="${actionName != 'show' ? false : true}"/>
    </div>
</div>
<div class="block2">   
    <label class="control-label">
        <g:message code="input.label" default="Input"/>
    </label>
    <div class="controls">
        <g:textField id="input2" name="input" value="${input}" readonly="${actionName != 'show' ? false : true}"/>
    </div>
</div>
<div class="block3">   
    <label class="control-label">
        <g:message code="input.label" default="Input"/>
    </label>
    <div class="controls">
        <g:textField id="input3" name="input" value="${input}" readonly="${actionName != 'show' ? false : true}"/>
    </div>
</div>

The form design above is correct, because in my form design, there will be several inputs of the same name (but each will be saved to the database under different primary keys) and it can be increases and decreases according to user selection.

Few questions using the above

  • How do i make it so that the value for input1 is params.input[0], input2 is params.input[1] and input3 is params.input[2] in the view? I can pass the model from controller without problem, but i couldn't distribute the value properly to each input on the form.
  • Is there any way to change the value ${input} dynamically? As in if i want to change the value to ${input[0]} or ${input[1]}
  • Can i automatically set the amount of block appended into the form using the g:each tag? Say like if from controller i want to set the rendering block amount to 3, so can i use the g:each tag to render the block 3 times in the form?


Thanks
 
Top