[CLOSED] Field Errors help

  1. #1

    [CLOSED] Field Errors help

    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:
    Click image for larger version. 

Name:	reqfail.png 
Views:	12 
Size:	11.3 KB 
ID:	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.
    Last edited by Daniil; Aug 27, 2013 at 4:57 AM. Reason: [CLOSED]
  2. #2
    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
  3. #3
    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.
  4. #4
    Need to use generic version of GetCmp
    var field = X.GetCmp<TextField>(fieldId);
  5. #5
    Thanks Vladimir. Oddly, using <TextField> works even for the ComboBox.
  6. #6
    Quote Originally Posted by jpadgett View Post
    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.
  7. #7
    Please post runable test sample reproduces the issue

Similar Threads

  1. Replies: 8
    Last Post: Jan 21, 2013, 4:22 PM
  2. Replies: 2
    Last Post: Nov 09, 2012, 3:23 PM
  3. Errors upgrading from Ext.Net 1.0 to 2.0
    By yash.kapoor in forum 2.x Help
    Replies: 2
    Last Post: Nov 08, 2012, 3:10 AM
  4. Replies: 2
    Last Post: Aug 19, 2011, 1:36 PM
  5. Publish Errors
    By Juls in forum 1.x Help
    Replies: 2
    Last Post: Jun 16, 2009, 2:54 PM

Posting Permissions