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

user1438
1#
user1438 Published in May 22, 2018, 4:35 am

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.307334 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO