RE: How to create readonly input text field where it should go as form data

Chetan Joshi, modified 6 Years ago. New Member Post: 1 Join Date: 3/8/19 Recent Posts
we have two different ways to achieve this with plain HTML <input> tag


1. readonly attribute -  where text field value will go in form data when user submits a form
2. disabled attribute - doesn't go with form dataas for as I checked with AUI library and gone through other community posts, we have only disabled attribute option.

I have a situation with input field that will be readonly on certain condition and it should go with formdata when I submit the form.
and I have aui required validator on it when it's not readonly.

Need help here.
Thanks
thumbnail
Mohammed Yasin, modified 6 Years ago. Liferay Master Posts: 593 Join Date: 8/8/14 Recent Posts
Hi,
You can use Custom Aui Validator  like this
<aui:validator name="custom" >
function(val,fieldNode,ruleValue) {
//Your Logic
return true;
}
</aui:validator>
 
thumbnail
Andrew Jardine, modified 6 Years ago. Liferay Legend Posts: 2416 Join Date: 12/22/10 Recent Posts
Hi Chetan,It's necessarily the most elegant, but you could manage this with a hidden field that has the same value as the disabled field. Alternatively, you the <input type="text"/> with the disabled attribute and just name sure you <portlet:namespace/>myVariable on the name so that the portlet namespace is added. One trick I have used in the past is to use the <aui:input/> tag ... deploy it .. and then in the browser use the inspector to grant the markup Liferay generated. That way it renders the same as the other <aui:input/> fields on your form. Just make sure, as I mentioned, that you replace the name copied from the browser with the namespace. 
thumbnail
Amos Fong, modified 6 Years ago. Liferay Legend Posts: 2047 Join Date: 10/7/08 Recent Posts
For readonly, what I usually do is add a hidden input for the real value to be submitted in the form. Then I just use normal html to display what you want the user to see or <aui:input type="resource".../> if you want it easily copy/pastable.