porno porno rokettube
Results 1 to 2 of 2

Thread: Question about repeatable input in grails form

  1. #1
    Junior Member
    Join Date
    Apr 2014
    Posts
    1

    Question about repeatable input in grails form

    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

  2. #2
    Administrator dave's Avatar
    Join Date
    Mar 2010
    Location
    West Yorkshire, UK - Valencia Spain
    Posts
    110
    The cleanest way and most maintainable approach would be to introduce a custom tag. This way you keep your preparation of the data/iteration count in code where it belongs before rendering a small gsp that represents the repeatable content.

    http://grails.org/doc/latest/guide/t...r.html#taglibs
    Connect with me on twitter : @davebrown1975 http://twitter.com/davebrown1975

    Web & Mobile Development by Tucanoo Solutions Ltd

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Forum Design by Tucanoo Solutions Ltd Grails Development Specialists.