View Full Version : setVisible with variable
Cichy
08-31-2007, 03:28 PM
Hello,
i want manage views Visible dynamicaly with what i get from form. The problem is, that i always get msg on debugger "call to undefined method 'setVisible'"
I try something like this, with no success:
----------
myvariable = form.getText();
...
<method event="onclick">
[myvariable()].setVisible(false);
</method>
-------------
Can someone tell me, how place value from var to ".setVisible()" to set what view i whant do "setVisible" (I have name of this view in variable)?
Benibur
09-01-2007, 12:17 AM
if i understand your question, the string stored in "myvariable" is the name of a view that you want to hide.
Let imagine that the views you may hide are in a view called "container".
Then you will access to your views with this syntax : container[myvariable].setVisible(false).
ex :
<text name="form">view1</text>
<view name="container">
<view name="view1"/>
<view name="view2"/>
</view>
<button onclick="parent.container[parent.form.getText()].setVisible(false)" />
you may encounter pb by doing all in a single instruction : try to separate the operations :
var myviewname = parent.form.getText();
var viewToHide = parent.container[ myviewname ];
viewToHide.setVisible(false);
let me know if this solve your pb and which syntax worked (or not )
Cichy
09-01-2007, 01:37 PM
Hello Benibur,
Thank You for helpful reply. You solve my problem, and give me some hints :)
Here is code (with little modification for my app) that work:
<canvas width="100%" height="100%" debug="true">
<view>
<view name="container">
<view name="blok01r" id="blok01r" x="100" width="100" height="100" bgcolor="red"/>
<view name="blok02r" id="blok02r" x="200" width="100" height="100" bgcolor="blue"/>
</view>
<edittext name="form">1</edittext>
<button y="200">
<method event="onclick">
var myviewname = parent.form.getText();
var tmp = ('blok0' + myviewname + 'r');
var viewToHide = parent.container[ tmp ];
viewToHide.setVisible(false);
</method>
</button>
</view>
</canvas>
Also i encounter another problem, that i tryed find view by "id", not "name". That make most of my errors, and i even don't know that. If you can delete view "name" from thic code, this will not work. So i just make path through many parents, childs in my app and, now this part of code work just as i wanted.
Thank you!
Benibur
09-02-2007, 01:38 AM
id is the global variable name that points to a specefic view, the syntax is therefor : gloabal[ myViewId ]
in your exemple :
<canvas width="100%" height="100%" debug="true">
<view>
<view name="container">
<view name="blok01r" id="blok01r_id" x="100" width="100" height="100" bgcolor="red"/>
<view name="blok02r" id="blok02r_id" x="200" width="100" height="100" bgcolor="blue"/>
</view>
<edittext name="form">1</edittext>
<button y="200" text="acces by name">
<method event="onclick">
var myviewname = parent.form.getText();
var tmp = ('blok0' + myviewname + 'r');
var viewToHide = parent.container[ tmp ];
viewToHide.setVisible(!viewToHide.visible);
</method>
</button>
<button y="230" text="acces by id">
<method event="onclick">
var myviewname = parent.form.getText();
var tmp = ('blok0' + myviewname + 'r_id');
var viewToHide = global[ tmp ];
viewToHide.setVisible(!viewToHide.visible);
</method>
</button>
</view>
</canvas>
tcheers,
ben
Cichy
09-02-2007, 01:40 PM
All working fine, with ID too.
Thank you again.
vBulletin® v3.8.4, Copyright ©2000-2012, Jelsoft Enterprises Ltd.