Adding the id field to the final HTML result of the GSP <g: form> tag

I am creating a GSP form that I want to submit using the call to $ .ajax ().

I understand that GSPs get renderings in the final HTML that the browser views, and therefore javascript can invoke regular HTML elements.

my form is created as such:

<g:form action="save" id="callmeForm" > <fieldset class="form"> <g:render template="form"/> </fieldset> <fieldset class="buttons"> <g:submitButton name="create" class="save" value="${message(code: 'default.button.create.label', default: 'Create')}" /> </fieldset> </g:form> 

but when the final form is displayed in HTML, it lacks the id field that I gave in the tag:

 <form action="/racetrack/callback/save/callmeForm" method="post" > <fieldset class="form"> etc... 

Is there a way to make the id property wrap so that I can reference the form by my id using javascript?

+4
source share
2 answers

You can use the name attribute, which sets both the name of the form tag and the identification attributes of the same value.

+9
source

Since you are using ajax to send to the server, why not just go with:

 <form id="callmeForm"> 

instead

What do you use with the gsp tag in this case?

Or you could try g: formRemote, which has interesting built-in functions: http://fbflex.wordpress.com/2010/05/09/adding-javascript-validation-to-formremote-ajax-forms-in-grails/

0
source

Source: https://habr.com/ru/post/1391217/


All Articles