Mar 29, 2011 7:33 AM
38 Posts
topic has been resolvedResolved

Editbox - ReadOnly property

  • Category: Other
  • Platform: Windows
  • Release: 8.5.2
  • Role: Developer
  • Tags: Xpages
  • Replies: 3
Here is the piece of code:

<input type="text" readOnly="True" name="readOnlyField" value="1234" />

<xp:inputText id="readOnlyFieldXPage" defaultValue="1234" readonly="true"></xp:inputText>

 The first line generates a field which is visible on the form but user cannot input anything into it. But the second line generates a span text. WHY???
 
This behaviour is WRONG!! Any ideas???
 
Regards, 
Naveen 
 
 
Mar 29, 2011 8:55 AM
38 Posts
Re: Editbox - ReadOnly property
Finally I was able to create workaround for this problem.
 
Created a script block like this: 
 
<xp:scriptBlock id="scriptBlock1" type="text/javascript">
  <xp:this.value><![CDATA[function makeReadOnly() {
 document.getElementById("#{id:readOnlyFieldXPage}").readOnly = true;
}
window.onload = makeReadOnly;]]></xp:this.value> 
 
This basically makes the field readonly via javascript when the page loads.
 
But this question is still OPEN... Why is Domino rendering the readonly field as text??? Is this a bug???
Mar 29, 2011 9:44 AM
39 Posts
Re: Editbox - ReadOnly property
Hi,
 
I know why your thinking it is wrong, but the problems is that when you set the readonly attribute on the <xp:inputText> control it does not just a pass through to the readonly attribute on an input control.....It works like you discovered, it changes the rendered html to a <span>  This is how it works inside of xpages, for instance if you have a form bound to an xpage and change from edit mode to read only it changes those from input's to span's  This is the way the control was coded to behave.  As you found you can always use client side javascript to change the readonly attribute if you need it changed.  I actually like the controls dual rendering functionality I think the span looks a lot nicer than an input box with a readonly attribute set to yes. Also you can style the two differently even though they are the same control without using css3 selectors.  You could create a new renderer for the control that would allow you have your read only attribute work like you want, but maybe overkill for what you are needing.
 
Thanks
-Toby
Mar 29, 2011 12:21 PM
38 Posts
Re: Editbox - ReadOnly property
Thanks Toby for the explanation. Atleast now I know this is not possible via property.
 
But you should note the help popup for the readonly property - "Indicates whether or not this control will prohibit changes by the user. This control may receive focus unless it has also been disabled."
 
Now you know the source of my confusion...  :)