Home dynamically add g:textField increasing index value using jquery in grails
Reply: 0

dynamically add g:textField increasing index value using jquery in grails

CCR
1#
CCR Published in 2018-01-09 11:32:39Z

I have a form field as below:

<div class="phase-form">
    <g:set var="x" value="${0}"></g:set>
    <g:each in="${projectInstance.phases}" status="j" var="phase">
        <g:hiddenField name="phases[$j].id" value="${phase.id}" />
        <g:textField name="phases[$j].phaseName"
            value="${phase.phaseName}"
            class=" ${hasErrors(bean: projectInstance, field: "phases[${j}].phaseName", 'error')}" />
        <br />
        <g:set var="x" value="$j"></g:set>
    </g:each>

    <g:textField name="phases[${x.toInteger()+1}].phaseName" value=""
        class="${hasErrors(bean: projectInstance, field: "phases[${x.toInteger()+1}].phaseName", 'error')}" />
    <button class="add-phase-button">
        <i class="fa fa-plus-circle"></i> <span class="text-obj"><g:message
                code="Phase" /></span>
    </button>
</div>

Here, I want to be able to add <g:textField name="phases[${x.toInteger()+1}].phaseName" value="" class="${hasErrors(bean: projectInstance, field: "phases[${x.toInteger()+1}].phaseName", 'error')}" /> this field dynamically using jQuery on click of .add-phase-button. I couldnot clone the field as it would take the same index of last field. Is there any better way to achieve this in grails?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.357635 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO