PDA

View Full Version : [CLOSED] Get unknown control type using ID



jpadgett
Jun 02, 2014, 6:50 PM
I am trying to write a generic method that accepts a DataServiceException message, parses out the validation errors, and then marks the indicated fields as invalid with the returned error message.

I am down to the part where I need to use X.GetCmp, or some such method, to call .MarkInvalid(error). I'm using X.GetCmp() instead of X.GetCmp<>() because I'm hoping to only know the control's ID, and not what type of control it is - thus allowing me to remain generic.

For example:


foreach (XElement err in validationErrors)
{
fieldId = err.Element("Field").Value;
errorMessage = err.Element("Error").Value;

var f = X.GetCmp<ComboBox>(fieldId);
f.MarkInvalid(errorMessage);
}


That example works - but I don't want to have to know if the returned field ID belongs to a ComboBox, or TextBox, etc. But X.GetCmp(fieldId) does NOT return an actual control. Furthermore, it actually returns an abstract BaseControl, which doesn't even have the MarkInvalid method off of it.

Is this possible? I thought I'd post in here in case someone had some sample code.

Thanks in advance ... Joel

geoffrey.mcgill
Jun 02, 2014, 8:06 PM
How about just looking for <Field>?

Example


var f = X.GetCmp<Field>(fieldId);

jpadgett
Jun 02, 2014, 9:34 PM
That throws the following design-time error:
http://forums.ext.net/attachment.php?attachmentid=11771&stc=1

Daniil
Jun 03, 2014, 2:00 PM
Hi @jpadgett,

Yes, it turns out that an abstract class cannot be used there.

If you just need to call a field's JavaScript method I can suggest an alternative solution.

X.Js.Call("App.fieldId.markInvalid", "Some Error");

jpadgett
Jun 04, 2014, 1:41 AM
Works great. Thanks!