Grails formRemote disabled field content isn't coming back as a param from GSP - grails

I am showing a text field on a GSP template that is in a formRemote and has content auto populated and is disabled (no editing allowed to user). When the form is submitted, I don't see the content of this field among the params going to the controller. I do see it when I remove the disabled="true" attribute from the text field. Any way to resolve this? Here is the field in question:
<label>Secondary ID:</label>&nbsp<g:textField name="secondaryId" disabled="true" style="border-radius: 5px" value="${recordToEdit ? recordToEdit.secondaryId : '' }"></g:textField>

Disabled form elements do not get submitted by the browser. You will need to enable the field(s) (through use of Javascript) prior to submitting the form.

Related

How to hide a field in editable mode in grails application using .gsp file?

I have a situation in my application where I need to hide a field in one editable mode, but be visible and editable in another editable mode. For instance, I have ownerEdit where it renders a file _userid.gsp and all fields in the _userid.gsp are editable. At the same time, I am trying to render _userid.gsp file in userEdit mode where I need to hide some fields completely.
Any suggestions are welcome. Here are the sample codes:
I have ownerdataEdit.gsp which is call in ownerEdit.gsp. The _ownerDataEdit.gsp indeed call _userid.gsp as
<g:render template = "userid" model="${[userEditable:!ownerView.equals('show')]}"/>
Similarly, userDataEdit.gsp also call _userid.gsp as
<g:render template = "userid" model="${[userEditable:userEdit]}"/>
And finally, the _userid.gsp has codes for the password field which I want to hide. And to do that I used if statement
<g:if test="${[userEdit:true]}"><dt input type="hidden"</dt></g:if>
<g:else>render the field </g:else>
For some reason it doesn't seem to be reading g:if condition.
You will need to pass the mode in the render model:
render(template: "userid", model: [editable: true])
Then you have some options.
You could take the trivial route and use style='display: none' on fields when editable is true. This has the added benefit of being able to easily toggle between editable and not client-side, if that has value to you.
You could use <input type='hidden' ... /> fields if you need the values to come through to any submission. Note that these can still be edited by a user who knows how to use the developer console, so you'll need to have protections in place on your server side as well to prevent malicious editing.
You could just not render the fields at all when you're not in editable mode, if you don't need them for anything.
Additional info:
Change your if conditions from:
<g:if test="${[userEdit:true]}"><dt input type="hidden"</dt></g:if>
to:
<g:if test="${userEditable}"><dt input type="hidden"</dt></g:if>

View hidden fields in the gsp code via if-operator in Grails

I am writing a form. If checkbox in this form is filled, some hidden fields in this form must be shown. This is a part of my form:
<div class="checkbox">
<label><g:checkBox name="isAdminCafee" value="${false}"/>Register as admin</label>
</div>
<g:if test="${isAdminCafee == true}">
some admin data
</g:if>
I've decided to use if-operator for solving this task, but when I set check-box on, hidden fields don't show. How to fix it?
It seems you are trying to show some admin data when user checks the checkbox and hide some admin data when user unchecks the checkbox.
You have used g:if tag library which is interpreted in the server and render the part inside it if the test condition is true.
Instead of using g:if tag library, you need to hide some admin data using css and use javascript to show or hide when user checks or unchecks the checkbox.

change default behavior of unobtrusive jquery validation to validate on onkeyup?

I'm using micrososofts unobtrusive jquery validation with MVC4 / razor and the default behavior appears to be to first validate on click of submit, and then after that validate onkeyup.
I'd like to change it so it starts validating onblur, and then after the first submit continues to validate on keyup as normal.
Is there a way I can change it to start validating on blur for all forms?
This is the default behaviour when using jquery validate directly or via Microsoft unobtrusive validation. If you enter a non valid entry into a field, that field will be validated on blur even before the field is submitted. If you focus and then blur a field without entering anything this field will only be validated on submitting the form.
From the documentation page section "A few things to look for when playing around with the demo"
Before a field is marked as invalid, the validation is lazy [but] if
the user enters something in a non-marked field, and tabs/clicks away
from it (blur the field), it is validated
I have forked the fiddle in the comment to demonstrate this using the unobtrusive plugin and some rendered html. http://jsfiddle.net/8wkS2/
"Links to jsfiddle.net must be accompanied by code." so here is the rendered markup produced by the server
<input type="text" name="field1" id="field1"
data-val="true"
data-val-required="This field is required"
data-val-length="The field LastName must be a string with a minimum length of 5."
data-val-length-min="5" />

In struts 2.0.14 the component <s:reset> button is not working after submitting the page?

I am using Struts2.0.14 for my application. I have a button to clear the textboxes. I have a few boxes which are stateful and values are persistent after the form is submitted.
My problem is that when I press the button before submitting the form it clears all values from the textboxes. But when I submit the form and press reset again, the textboxes do not reset.
I'm not sure if this is your problem, but: to "reset" the fields of an HTML form is not the same as to "clear" them, it just means to reset their values to their "default" values, those that were set (typically) in the value="..." attribute of the field tag.
Now, consider the typical server-side form validation workflow, when the user has entered some field values, submited the form, and get it back from the server with some errors marked (typically in Struts2, this corresponds to the INPUT result). Here, the new HTML page that is returned to the user will have its form fields filled with the previously submitted values. Now, from the client side perspective, those are the "default" values of the form: if you "reset" the form (perhaps after editing it), those are the values that will be restored.

clear all input components

I have 1 jsp form whcih take user detail and after clicking on submit button its store the data into DB and success message is displaying on the top of the GUI
but the problem is all the data iin the input boxes are not clear, data remain same in the input boxes
i m using struts2
can any body tell me how to clear all input boxes
Thanks
shakil
One option is to use a javascript to reset the form when the user clicks on submit. To do this, add the following javascript to your submit button (change 'form' to be the name of your form):
<s:submit value="Save" onclick="this.form.reset();" />
You could also use the Struts 2 JQuery Plugin which has a special tag for this purpose.
Better You set the the null value in model object in Action class of after store the data in DB and before return success
example if you have User object , you set user.setUserName(""); user.setPassword("")

Resources