PDA

View Full Version : [CLOSED] Problem with Combobox Select Handler



matrixwebtech
Nov 05, 2014, 6:45 AM
Hi,
In my example I have a combobox and a Button and with combox's Select.Handler I set the button's visibility.but problem is if I not set a delay for select Handler there are a java-script error so I set

l.Select.Delay = 1;
java-script error is resolved and the code works fine,but the problem is the button visible once and next moment disrepair.which is not looks good,if set

l.Select.Delay = 100;
then its understand properly.Is there any other way to this.

EXAMPLE VIEW


@model e.Controllers.combobox
@{
Layout = null;
var X = Html.X();
}

@X.ResourceManager()

@(X.ComboBoxFor(obj=>obj.selected)
.FireSelectOnLoad(true)
.Items
(
new ListItem("Yes",true),
new ListItem("No",false)
)
.Listeners(l=>{
l.Select.Delay = 50;
l.Select.Handler=@"var v=this.getValue()

if(Ext.isDefined(v)==true && v=='true')
{
App.btn.setVisible(true);
}
else
{
App.btn.setVisible(false);
}
";
}))
@(X.Button().ID("btn").Text("Button"))

Example Controller


public class cobbo_selected_changeController : Controller
{
//
// GET: /cobbo_selected_change/

public ActionResult Index()
{
combobox _combobox = new combobox();
_combobox.selected = false;
return View(_combobox);
}

}

public class combobox
{
public bool selected { get; set; }
}

Daniil
Nov 05, 2014, 1:29 PM
Hi @matrixwebtech,

A JavaScript error happens, because the "App.btn" is not created yet by the time when the Select listener is executed at the first time. The Button is not created yet at all.

I can suggest to hide the Button via its (the Button's) BeforeRender listener.

Another approach is to set .Hidden(true) for the Button initially.

matrixwebtech
Nov 05, 2014, 3:08 PM
Hi Daniil,thanks for reply,but may I try with 2nd approach,but not working.


Another approach is to set .Hidden(true) for the Button initially.

X.Button().ID("btn").Text("Button")
.Hidden(true)

Daniil
Nov 05, 2014, 3:33 PM
You should still use Delay with that approach. Do you use?

matrixwebtech
Nov 05, 2014, 3:49 PM
No I not use Delay for this case I need a solution without delay.because in original forms I don't know how long it will take to create ,so if I put any delay,may be the button create before this or after this.

So Daniil ,can you please refer me any script with which I can understand the button is created and I put

l.Select.Handler=@"var v=this.getValue()

if(Ext.isDefined(v)==true && v=='true')
{
App.btn.setVisible(true);
}
else
{
App.btn.setVisible(false);
}
";
after that.

Daniil
Nov 05, 2014, 5:29 PM
because in original forms I don't know how long it will take to create ,so if I put any delay,may be the button create before this or after this.

Could you, please, clarify why it is a problem? I don't foresee any problems with that, everything should be OK. Have you tried or just reject the idea entirely?:)


So Daniil ,can you please refer me any script with which I can understand the button is created and I put

You can check it this way.

if (App.btn) {
alert("The Button is created.");
} else {
alert("The Button is not created.");
}

Though, I don't see how it helps in your scenario.

matrixwebtech
Nov 05, 2014, 6:16 PM
I tried both

I can suggest to hide the Button via its (the Button's) BeforeRender listener.

Another approach is to set .Hidden(true) for the Button initially.
but not working,and after that I take all componet inside a viewport and put the code in
viewport's

l.AfterRender.Handler and now its working fine.
thanks for your help.