PDA

View Full Version : [CLOSED] Field Errors help



jpadgett
Aug 15, 2013, 5:40 PM
Just in case someone recognizes this and/or knows off hand what I need to include in order to fix this, I'm not putting full sample code in yet. If a sample is needed I will post it.

I am using MVC Razor.

I was following the Models > Submit example (http://mvc.ext.net/#/Models/Submit/) for displaying validation messages that come back from a data service. I have parsed the message and successfully filled a FieldErrors collection. Here is some of the code I'm using:



@(Html.X().FormPanel()
.ID("Form1")
.BodyPadding(5)
.FieldDefaults(def =>
{
def.MsgTarget = MessageTarget.Side;
})
.Buttons(
Html.X().Button()
.Text("Submit")
.DirectEvents(de =>
{
de.Click.Url = Url.Action("Submit");
de.Click.EventMask.ShowMask = true;
de.Click.FormID = "Form1";
})
)
.Items(
Html.X().TextFieldFor(m => m.Fund.ShortName).FieldLabel("Short Name"),
Html.X().TextFieldFor(m => m.Fund.LegalName).FieldLabel("Legal Name"),
Html.X().TextFieldFor(m => m.Fund.Cusip).FieldLabel("Cusip"),
Html.X().ComboBoxFor(m => m.Fund.FundStructure)
.FieldLabel("Fund Structure")
.Store(
Html.X().StoreFor(m => m.FundStructures)
)
.ValueField("FundStructureId")
.DisplayField("Description")
)
)




public ActionResult Submit(Fund fund)
{

try {
...
}
catch (DataServiceRequestException dse)
{
string fieldId;
string errorMessage;
var fieldErrors = new FieldErrors();

...

foreach (XElement error in errors)
{
fieldId = "Fund_" + error.Element("Field").Value;
errorMessage = error.Element("Error").Value;

fieldErrors.Add(new FieldError(fieldId, errorMessage));
}

return this.FormPanel(fieldErrors);
}

return this.Direct()
)


When the response is sent to the view, however, instead of marking the fields as invalid and showing the error message, I get this:
6766

Again - in case it's something silly on my part, I'm posting without full code sample, but I will provide a full sample if needed.

Vladimir
Aug 15, 2013, 6:09 PM
You cannot use FormPanelResult for DirectEvent requests, FormPanelResult is designed for from requests only (requests are initiated by FormPanel, for example App.FormPanel1.submit(....))

In your case, DirectResult can be used only

jpadgett
Aug 15, 2013, 7:00 PM
How, then, do I mark the fields as invalid and populate the error message?

I tried:


var f = X.GetCmp(fieldId);

if (f is TextField) ((TextField)f).MarkInvalid(errorMessage);
else if (f is ComboBox) ((ComboBox)f).MarkInvalid(errorMessage);


But nothing happened. I watched in debug and var f was always null - even though the field id was correct. I assumed the ActionResult Submit didn't know about the form and so could not "get" the controls.

Vladimir
Aug 15, 2013, 8:11 PM
Need to use generic version of GetCmp


var field = X.GetCmp<TextField>(fieldId);

jpadgett
Aug 16, 2013, 7:17 PM
Thanks Vladimir. Oddly, using <TextField> works even for the ComboBox.

jpadgett
Aug 19, 2013, 3:52 PM
Thanks Vladimir. Oddly, using <TextField> works even for the ComboBox.

I have to *edit* that... it was working at first, but after restarting the app, the validation only works for the TextField controls.

Vladimir
Aug 19, 2013, 4:08 PM
Please post runable test sample reproduces the issue