PDA

View Full Version : [CLOSED] Set Focus on blank field



matrixwebtech
Sep 26, 2014, 7:58 AM
@{
var X = Html.X();
}
<script type="text/javascript">
var validation = function () {


if (Ext.getCmp("f").isValid() == true) {
return true;
}
else {
return false;
}
}

</script>
@X.ResourceManager()
@(
X.FormPanel().ID("f")
.Items
(
X.TabPanel()
.Items
(
X.Panel().Title("Tab 1").ID("t1")
.Items
(
X.TextField().FieldLabel("Field 1")
.ID("f1")


)
,
X.Panel().Title("Tab 2").ID("t2")
.Items
(
X.TextField().FieldLabel("Field 2")
.AllowBlank(false)
.ID("f2")

)
,
X.Panel().Title("Tab 3").ID("t3")
.Items
(
X.TextField().FieldLabel("Field 3")
.AllowBlank(false)
.ID("f3")

)

)



)
.Buttons
(
X.Button().Text("Click")
.Listeners(l =>
{
l.Click.Handler = "return validation()";
})



)


)


above is my sample code.I have 3 tabs and each tab contains a textfield.and every field is

.AllowBlank(false)
My requirement is
I want to set focus on black field in each tab sequentially,

suppose I am on Tab 1 and click on button its take me to Tab 3 with focus on Field 3 if this field is blank.

Daniil
Sep 26, 2014, 11:46 AM
Hi @matrixwebtech,

So, the task #1 is to determine what TextField is to going to be focused.

Using this code you can determine the field is empty or not.

Ext.isEmpty(App.TextFied1.getValue());

Then you should activate the tab with that field. I would try this code:

textFieldToFocus.up("tabpanel").setActiveTab(textFieldToFocus.up("panel"));

Then you could finally focus the field:

textFieldToFocus.focus();

I have not tested it. So, you might need to correct something.

matrixwebtech
Sep 26, 2014, 12:45 PM
Thanks ,working fine,please close.