3.2.0

Is it possible to change ID onfly

Is it possible to change object ID's (setID) onfly?
Oddbjørn
April 10,
Yes, sure. Maybe I don't understand your question - could you explain what you are trying to do?
Alex (ActiveWidgets)
April 10,

Eks.

1. I have made a button with id='oldname' written to HTML.
2. Then I have a visual userinterface where the user can change all kind of (AW.UI) properties of the button.
3. And I want to give the user ability to change the id to what ever they want eks. 'newname'.

Maybe it is easier to show in codes, what I want.

function (oldname,newname){
var oldobj=AW.object("oldname");
oldobj.setId("newname");
oldobj.refresh();
}

The "new named" object is not working correctly anymore.

Thanks
Oddbjørn
April 10,
Oddbjørn, I am also not sure of the intention:

in your code shouldn't it read ?
function SOMETHING(oldname,newname){


And if oldname and newname are parameters, shouldn't it be into the function without doublecuotes ?
var oldobj=AW.object(oldname);
oldobj.setId(newname);


I made the simplest sample trying to discover what's wrong, and found
that oldobj.setId(newname) is thowing an alert. (but the rest seems ok to me)
Alex, is this normal ?
var obj = new AW.UI.Grid; 
obj.setId('grid1');
obj.setCellText(function(i,j){return j + '-' + i}); 
obj.setHeaderText(function(i){return 'header-'+ + i}); 
obj.setColumnCount(4); 
obj.setRowCount(5); 
document.write(obj ); 

var DivOne = new AW.HTML.DIV;
DivOne.setId('d1');
document.write(DivOne ); 

var Ab2 = new AW.UI.Button; 
Ab2.setId('hhh'); 
Ab2.onControlClicked = function(){
changeId( 'grid1', 'NEW-ID');
}
 
document.write(Ab2 ); 

function changeId(oldname,newname){
var oldobj=AW.object(oldname);
oldobj.setId("newname");
oldobj.onCellClicked = function(){ alert(this.getId())}
DivOne.setContent('html', oldobj.toString());
DivOne.refresh();
}
Carlos
April 10,
Thanks alot, but a little embarassed. It's so simple.

I had tested it before, and I didn't get the old object away, and I don't think you got the old object away (it's just a copy with new name and with lost connection).

Still:
1. I put the "old" grid inside DivOne right away
2. Then I changed the name your way

It seems to be perfect.

Thanks again.



Oddbjørn
April 11,
The unique id is used to find the html element which corresponds to the given AW object. So if you want to change the id, you have to remove old html element and insert new one with the new id.
Alex (ActiveWidgets)
April 11,

This topic is archived.

See also:


Back to support forum