PDA

View Full Version : [CLOSED] Find Field in Panel



AmitM
Oct 29, 2013, 3:11 AM
How do I find a field in a panel? The view is used in multiple places, so the Panel has a dynamic ID, as do the fields in the panel. The basic idea is to enable the "Other" text field when "Other" is choosen from the dropdown.



Html.X().ComboBoxFor(m => m.BirthCountry, false)
.Icon(Model.IsLocked ? Icon.Lock : Icon.None)
.ReadOnly(Model.IsLocked)
.FieldLabel("Birth Country")
.ValueField("BirthCountryID")
.DisplayField("Description")
.Store(Html.X().Store()
.Model(Html.X().Model()
.Fields(
new ModelField("BirthCountryID"),
new ModelField("Description")
).IDProperty("BirthCountryID")
)
.DataSource(Model.BirthCountries))
.Listeners(ls => {
ls.Select.Handler = "if (this.getValue() == 10) alert('setDisabled(false);";
}),

Html.X().TextFieldFor(m => m.BirthCountryOther, false)
.Icon(Model.IsLocked ? Icon.Lock : Icon.None)
.Disabled(Model.BirthCountry != 10)
.ReadOnly(Model.IsLocked)
.FieldLabel("Birth Country Other"),


I did see the example that used FieldSet, but I would like to keep the appearance as-is.

Thanks,
Amit

AmitM
Oct 29, 2013, 3:23 AM
I found the answer:



ls.Select.Handler = @"var formPanel = this.up('form');
var tf = formPanel.down('[name=BirthCountryOther]');
if (this.getValue() == 10) tf.setDisabled(false);
else {tf.setDisabled(true); tf.setValue('');}";


Thanks,
Amit

geoffrey.mcgill
Oct 29, 2013, 3:54 AM
Hi Amit,

Glad to see you found the answer. I have one very minor suggestion that might help avoid a JavaScript error in the future. Add curly braces around your "if" statement, same as you have done around your "else".

Example


var tf = formPanel.down('[name=BirthCountryOther]');
if (this.getValue() == 10) { tf.setDisabled(false); }
else {tf.setDisabled(true); tf.setValue('');}";

If we ever introduce script minimization/optimization into the .Handler property, your code might fail because the "if" and "else" will be minimized into one line.

Hope this helps.