How to pass disabled textbox value in Rails? - ruby-on-rails

How may i pass disabled textbox value on controller side ?
Right now i am getting nil value for the disabled textbox.

This is an http thing, if you disable a form element it does not get sent over the wire. You can either set the readonly='true' attribute with javascript and style it to appear disabled, or use javascript to copy the value to a hidden field. unfortunately, you there is no way to just tell it to send.

Related

Grails datepicker looses setting

I've noticed that datepicker is reset to default value after the request has been done and the page reloaded.
Although I ensured that parameters are saved for use in pagination
...
<g:paginate total="${totalCount}" id="${params.id}"
params="[
startDate : params.startDate,
startDate_year : params.startDate_year,
startDate_month: params.startDate_month,
startDate_day : params.startDate_day]
/>
...
and it works as expected, the UI component itself shows default value. I'm afraid that it may irritate users. What should be done to make datepicker display the last value set by user and not the default one?
Your <g:paginate> tag is using the params appropriately, but your <g:datePicker> tag likely does not use a value attribute set to whatever was submitted.

Prevent a hidden field from postback

Is it possible to prevent a hidden field from posting its value back to the server? The purpose of it is to render a large list of comma separated values that I need to know in the client but I do not want to post back.
Thanks,

Grails : Using select tag of grails with disabled property set to true ignores the value

I need to disable a select element in grails depending on its value. The problem is when I started to add the disable property something is quite wrong with the code.
An example is when the form is sent to the backend, its as if there is no value for that select element and the value sent is null. But, when I checked the DOM, there is a selected attribute in the element. I tried to remove that disabled property because I have a feeling that it has something to do with the bug that I'm encountering and I was right because after removing it, everything worked correctly again.
this is the select tag
<g:select name="detail-entryNameId"
value="${journalEntryName.savingId}"
from="${journalEntryNameInstanceList}"
optionKey="savingId"
optionValue="displayName"
readonly="${journalEntryInstance.paymentMade}"
/>
One more thing about this element is that it can occur as many as possible, which means I have a table and in every row, that element exist so I cannot simply manipulate it.
I've also read in this post how can i make a textfield read only in grails? that "If you use disabled="true" the value will not actually be submitted in the form, so the <g:field/> tag should be used." which proves that disable attribute affects the value of the element.
How can I disable the select element and at the same time, still get its value correctly?
The problem is that in HTML the mere existence of the disabled attribute disables the tag. The value of the attribute (true/false) is ignored.
In such cases the solution is to use an <g:if> to create the tag with or without the disabled attribute according to a condition.
In your case, since you want the value even when the tag is disabled you can add a <g:hiddenField> with the same name and value as the disabled select.

Duplicate hash key in request when posting a form with a checkbox using rails

I have a checkbox iagree and when I am submitting the form I am getting
obj[iagree] : 0
obj[iagree] : 1
in the request. I don't know why is this?
This is expected when using form helpers like check_box_tag.
This helper create a hidden field just before the check box with the same name and the value 0.
The reason for this hidden field is to solve the issue, that the browser sends no parameter at all when a check box is unchecked.
So it is not possible to destingish, whether there is no check box in the form or the check box is uncheced.
With this workaround an unchecked check box is returned with value 0 and a checked checkbox with value 1.
The second parameter just overwrites the hidden field, if checked.
In your params[] you will always see obj[iagree] with either 0 or 1.

Validation of date input into textbox when using JQueryUI Datepicker

I have a textbox that I've attached the datepicker to. If the user enters the date via the datepicker all is well but they also have the ability to go in and enter a bad date directly into the textbox. i.e. 1/55/1995
Can the text box be disabled so only the calendar can be used?
How are people preventing this?
Looks like what you need is to just disable the field or make it readonly. Check out this answer How can I disable all keyboard keys?
I would say readonly is the better option because it still allows the value to be retrieved when it is posted back; don't think disabled fields get picked up.
You can validate the input text, if entered manually to the textbox.
Have a look at the url below,
http://keith-wood.name/uiDatepickerValidation.html
Hope this helps.
Cheers

Resources