3.0 beta 2

Disable input edit box?

How do you disable a control, more specifically the input box. I tried to set the disabled attribute to false and it 'looked' like it worked, it did turn the text a light gray, but you can still edit the text. I tried:

obj.setAttribute('disabled', true);


Also, with the input box, I tried to set the background color to silver (this is how we visually display disabled edit boxes) and the input box did have a silver background but the text still had the white background. Is there a single property I can change to set all of the background to one color?
Jim Hunter
October 6,
Yeah I am interested in that too...
JeanLuc
October 19,
Is there an answer to this posted question?
Ismael
November 18,
Try obj.setAttribute('disabled', 'disabled');
Rick Villela
November 18,
If readonly attribute is set, I can disable editing, but somehow once is done it can not be reversed (to enable it again - i.e. false)... Why???

obj.getContent('box/text').setAttribute('readonly', true);

Carlos
December 19,

If readonly attribute is set, I can disable editing, but somehow once is done it can not be reversed (to enable it again - i.e. false)... Why???

That is because the HTML specification says that attributes such as readonly, disabled need not have a value. All you need to do is to make sure that the attribute is there. Likewise, the XHTML spec asks developers to give the same entity as its value.. that is readonly="readonly" this will not lead to the confusion that happen due to boolean values.

So the answer is to remove the property (but not set it to false)

obj.getContent('box/text').removeAttribute('readonly');


HTH
Md. Sheriff, Drivestream
December 19,
Thanks a lot for the quick answer,
I can not get the supposed result .
Am I missing something basic ??

var SInput= new AW.UI.Input;
SInput.getContent('box/text').setAttribute('readonly', 'readonly');
document.write(SInput);
 
var button1 = new AW.UI.Button;
button1.setControlSize(90);
button1.setControlText("Enable edit");
  
button1.onControlClicked = function(event){
SInput.getContent('box/text').removeAttribute('readonly');
  }
 document.write(button1);
      
var button2 = new AW.UI.Button;
button2.setControlSize(90);
button2.setControlText("Disable edit");
  
button2.onControlClicked = function(event){
SInput.getContent('box/text').setAttribute('readonly', 'readonly');
  }
 document.write(button2);
Carlos
December 19,
Hi Carlos,

For a moment, i thought .getContent('box/text') returns the real DOM element refernce of the textbox.. But, it turned out to be yet another custom object reference mapping to that element.. So this should work fine (it worked for me):

button1.onControlClicked = function(event){
SInput.getContent('box/text').setAttribute('readonly', '');
}


HTH
Md. Sheriff, Drivestream
December 20,
Sorry guys, I am really missing something here.

Using 2.0 RC1, IE6 and examples/quickref/input.htm, if I insert the line
obj.getContent('box/text').setAttribute('readonly', true);

before the line
document.write(obj);

it doesn't seem to make any difference: I can still type stuff into the control.

Please, can anyone help?
LostInSpace
February 2,
That attribute isn't a true/false attribute, it is a READONLY or nothing attribute. And I do not know of a way to remove the readonly setting once it's set. I think that if you use:

obj.getContent('box/text').setAttribute('readonly', 'readonly');


it will set the control to readonly and this might set it back to normal:

obj.getContent('box/text').setAttribute('readonly', 'anything');


Not sure if this will work but it should.
Jim Hunter (www.FriendsOfAW.com)
February 3,
actually, I think the real way to remove the readonly attribute is:

obj.getContent('box/text').removeAttribute('readonly');
Jim Hunter (www.FriendsOfAW.com)
February 3,
Sorry, still stuck. Even
setAttribute('readonly', 'readonly')
does not work. Here's the example code in its entirety. This is just examples/quickref/input.htm with the one line inserted. My expectation is that when I click on the input box, then typing would not change it's contents.

I would really appreciate someone telling me what I'm doing wrong.

<html>
<head>
    <script src="../../runtime/lib/aw.js"></script>
    <link href="../../runtime/styles/xp/aw.css" rel="stylesheet"></link>
</head>
<body>
<style>
    #myInput {width: 150px; height: 25px}
</style>

<p style="font:menu">
    see page source
</p>

<script>
    var obj = new AW.UI.Input;
    obj.setId("myInput");	// necessary for CSS rules
    obj.setControlText("Some text");
    obj.setControlImage("favorites");
    obj.getContent('box/text').setAttribute('readonly', 'readonly');  
    obj.onactivate = function() { return false; }
    obj.onkeydown = function() { return false; }
    obj.onkeypress = function() { return false; }
    document.write(obj);
</script>

<script>
    obj.onControlClicked = function(event){ window.status = "Control clicked"};
    obj.onControlDoubleClicked = function(event){ window.status = "Control double clicked"};
    obj.onControlMouseOver = function(event){ window.status = "Control mouse over"};
    obj.onControlMouseOut = function(event){ window.status = "Control mouse out"};
    obj.onControlMouseDown = function(event){ window.status = "Control mouse down"};
    obj.onControlMouseUp = function(event){ window.status = "Control mouse up"};
    obj.onControlTextChanged = function(text){ window.status = "control text: " + text };
</script>

<p></p>

<script>
    var button = new AW.UI.Button;
    button.setControlText("Click me");
    document.write(button);

    button.onClick = function(){
    alert("input text: " + obj.getControlText());

    obj.setControlText("other text");
        alert("input text: " + obj.getControlText());

    }
</script>
</body>
</html>
LostInSpace
February 5,
Try:

obj.getContent('box/text').setAttribute('readonly', true); 
    obj.onControlActivated = function(){ return true; }


See related post at:
/datagrid.9294/dropdown-control-instead-of-combo.html
Rob Francis
February 5,
for IE, the readonly attribute is case-sensitive.

Try: obj.setAttribute('readOnly',true);

Grant
May 4,
How to use check box in a Active.Controls.Grid
susi
August 2,
<TEXTAREA name=filedata></TEXTAREA>
document.getElementById('filedata').disabled=true;
document.getElementById('filedata').disabled=false;

worked for me in the past

dermot
August 7,
TEXTAREA name=filedata></TEXTAREA>
document.getElementById('filedata').disabled=true;
document.getElementById('filedata').disabled=false
gulshan sharma
October 5,

Hi,

In trying to crack the in-disable-able input box:
<code>
obj.getContent("box/text").setAttribute("readonly",true);
obj.getContent("box/text").setAttribute("readonly","readonly");
</code>etc...

I find these don't work.


It appears as though even the getContent(...) method is not working for me. alert(obj.getContent("box/text")) is raising errors. In Mozilla: Error: uncaught exception: [Exception... "Could not convert JavaScript argument" nsresult: "0x80570009 (NS_ERROR_XPC_BAD_CONVERT_JS)" location: "JS frame :: http://mywebpage.php :: prdE_edit :: line 141" data: no]. And in IE it just says "Object doesn't support this property or method".


I can work around okay though if the object is already written in the HTML then I do:
<code>document.getElementById("obj-box-text").setAttribute("readonly",true)</code>

Has anyone had problems like this?
Shawn
December 7,
Hmm.. appears it was happening cause I was putting the input in the innerHTML() of another object? It works okay if I call obj.toString(); before adding the input control to the parent object. (Weird.)
Shawn
December 7,

Ok everyone, go to the following post:

/javascript.forum.17803.0/bug-caching-of-the-html.html

it concerns almost every getContent("box/text").setAttribute() call you do.

(EXCERPT from Alex /javascript.forum.16359.7/input-text-and-input-password.html)

...
This is a bug in AW related to the caching of the html fragments. The workaround is to clear html cache manually on the control and intermediary level ('box' content).
...

John Mason
December 22,

This topic is archived.

See also:


Back to support forum

Search

Version 2

Looking for AW 2.6 ?
The old site is here.