[CLOSED] RemoteValidation error remains after changing via directevent

  1. #1

    [CLOSED] RemoteValidation error remains after changing via directevent

    Hi,
    I'm a little bit stuck :

    I have a textfield with remotevalidation :

                                                            Html.X().TextFieldFor(m => m.ES_TRANS_KK)
                                                            .ID("txt_ES_TRANS_KK")
                                                            .Width(150)
                                                            .FieldLabel("Krankenkassennr.")
                                                            .LabelAlign(LabelAlign.Top)
                                                            .Listeners(li => { li.Change.Handler = "setVersicherter();"; })
                                                            .IsRemoteValidation(true)
                                                            .MsgTarget(MessageTarget.Qtip)
                                                            .ValidateOnChange(true)
                                                            .ValidateOnChange(true)
                                                            
                                                            .RemoteValidation(rv =>
                                                            {
                                                                rv.Url = "/Home/isES_TRANS_KKValid";
                                                                rv.Method = Ext.Net.HttpMethod.POST;
                                                                rv.EventOwner = ValidationEventOwner.Input;
                                                                rv.ValidationEvent = "blur";
                                                                rv.Delay = 0;
                                                            })
                                                            .DirectEvents(de =>
                                                            {
                                                                de.Blur.Url = Url.Action("settxt_KK_NAME_TRANS");
                                                                de.Blur.ExtraParams.Add(new Parameter("ES_TRANS_KK", "this.value", ParameterMode.Raw));
                                                            })
    This works fine.
    When I change the fields value by typing a wrong text, the error shows, what's the expected behaviour.
    Then I open a window with values, and by doubleclick I execute the following :

            public ActionResult DirectEventKrankenkasseTransClicked(String KK_ID)
            {
                try
                {
                    var window_KK_KrankenkasseTrans = this.GetCmp<Window>("window_KK_KrankenkasseTrans");
                    window_KK_KrankenkasseTrans.Close();
                    KK_Krankenkasse kasse = db.KK_Krankenkasse.First(m => m.KK_ID == KK_ID);
    
                    var txt_KK_NAME_TRANS = this.GetCmp<TextField>("txt_KK_NAME_TRANS");
                    txt_KK_NAME_TRANS.SetValue(kasse.KK_Name);   //<- HERE I SET THE VALUE TO A VALID VALUE
                    var txt_ES_TRANS_KK = this.GetCmp<TextField>("txt_ES_TRANS_KK");
                    txt_ES_TRANS_KK.SetValue(kasse.KK_ID);
                    //txt_ES_TRANS_KK.FireEvent("blur"); <---- THIS DOESN'T WORK
                    //txt_ES_TRANS_KK.Validate(); <------ THIS DOESN'T WORK
                    //X.Js.Call("blurAndValidateField", "txt_ES_TRANS_KK"); <------ HERE I TRIED TO DO IT DIRECTLY, DIDN'T WORK
                    return this.Direct();
                }
                catch (Exception e)
                {
                    Console.WriteLine("{0} Exception caught.", e);
                    X.Msg.Alert("Error", e.Message).Show();
                    return this.Direct();
                }
            }
    After the window closes, the value is displayed correctly, but the validation stays false and the field
    is invalid. If I manually go inside the field, the blur event is called and the field is validated and the error
    is gone. But only if I do it manually.
    I want the field to be valid.

    That's the method, that does the validation :

            public JsonResult isES_TRANS_KKValid(string value)
            {
                JsonResult result = new JsonResult();
                bool KK_IDExists = db.KK_Krankenkasse.Any(m => m.KK_ID == value) || String.IsNullOrEmpty(value);
    
                if (KK_IDExists)
                {
                    result = createJSONResultForValidation(value, true, "");
                }
                else
                {
                    result = createJSONResultForValidation("Kasse existiert nicht !", false,"");
                }
                return result;
            }
    
            private JsonResult createJSONResultForValidation(string value, bool caseValid, string jscript)
            {
                JsonResult result = new JsonResult();
                Object Data = new
                {
                    message = value,
                    valid = caseValid,
                    script = jscript
                };
                result.Data = Data;
                return result;
            }
    When I try to blur the field by code, it doesn't work

    function blurAndValidateField(fieldId) {
        blurAndValidateField
        var cmp = Ext.getCmp(fieldId);
        cmp.fireEvent("blur");
        var isValid = cmp.isValid();
        if (isDebug) {
            console.log("blurAndValidateField : " + isValid);
        }
        //cmp.clearInvalid();
        //cmp.validate();
        //cmp.isValid();
        //validateForm();
    }
    How can I get the field to be valid ???

    Regards,
    Holger
    Last edited by Daniil; Dec 07, 2012 at 6:46 AM. Reason: [CLOSED]
  2. #2

    OMG

    I think I found it, <---- wrong

    rv.EventOwner = ValidationEventOwner.Input;
    Should be
    rv.EventOwner = ValidationEventOwner.Field;
    Why did I use Input ?
    And what is it for ?

    Regards,
    Holger
    Last edited by zwf; Dec 03, 2012 at 2:18 PM. Reason: Didn't find it :(
  3. #3
    OK,
    the following seems to fix it partially :

    function blurAndValidateField(fieldId) {
        
        var cmp = Ext.getCmp(fieldId);
        cmp.fireEvent("blur");
    
    }
    Partially, because the errormessage remains only as popup, when I
    hover over the field.
    The red marker is gone, but the popup error remains.

    ???
    Regards,
    Holger
  4. #4
    Hi Holger,

    I see how you are trying to achieve something, but do not understand well what you need to get.

    Could you clarify why do you validate a field in the Blur event if RemoteValidation is actually made for that?

    Maybe do you need RemoteValidation to be triggered on blur...

    Please clarify the requirement.

    Quote Originally Posted by zwf View Post
    I think I found it, <---- wrong

    rv.EventOwner = ValidationEventOwner.Input;
    Should be
    rv.EventOwner = ValidationEventOwner.Field;
    Why did I use Input ?
    And what is it for ?
    It is an owner of ValidationEvent. It can be a field itself, i.e. a component.

    Or its input element:
    http://docs.sencha.com/ext-js/4-1/#!...operty-inputEl
  5. #5
    OK,

    I open a window from the main page and in an directevent (from the window) I change the value of the field and close the window.
    This field has a remotevalidation, that checks, if the value is in the database (can be entered manually
    OR with the popupwindow).

    So, the field should be remotevalidated when I entered a value AND
    when I changed the value from the directevent.

    Regards,
    Holger
  6. #6
    To trigger remote validation you can call the field's JavaScript performRemoteValidation method.

    Example
    <%@ Page Language="C#" %>
     
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        protected void CheckField(object sender, RemoteValidationEventArgs e)
        {
            bool success = true;
            
            if (e.Value.ToString() != "Valid")
            {
                e.ErrorMessage = "Only 'Valid' is valid";
                success = false;
            }
    
            e.Success = success;
        }
    
        protected void Change(object sender, DirectEventArgs e)
        {
            this.TextField1.Text = "some text";
            this.TextField1.Call("performRemoteValidation");
        }
    </script>
    
    <!DOCTYPE html>
    
    <html>
    <head runat="server">
        <title>Ext.NET v2 Example</title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
    
            <ext:TextField ID="TextField1" runat="server" IsRemoteValidation="true">
                <RemoteValidation OnValidation="CheckField" />
            </ext:TextField>
    
            <ext:Button runat="server" Text="Change" OnDirectClick="Change" />
        </form>
    </body>
    </html>
  7. #7
    Quote Originally Posted by Daniil View Post
    To trigger remote validation you can call the field's JavaScript performRemoteValidation method.

    Example
    <%@ Page Language="C#" %>
     
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        protected void CheckField(object sender, RemoteValidationEventArgs e)
        {
            bool success = true;
            
            if (e.Value.ToString() != "Valid")
            {
                e.ErrorMessage = "Only 'Valid' is valid";
                success = false;
            }
    
            e.Success = success;
        }
    
        protected void Change(object sender, DirectEventArgs e)
        {
            this.TextField1.Text = "some text";
            this.TextField1.Call("performRemoteValidation");
        }
    </script>
    
    <!DOCTYPE html>
    
    <html>
    <head runat="server">
        <title>Ext.NET v2 Example</title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
    
            <ext:TextField ID="TextField1" runat="server" IsRemoteValidation="true">
                <RemoteValidation OnValidation="CheckField" />
            </ext:TextField>
    
            <ext:Button runat="server" Text="Change" OnDirectClick="Change" />
        </form>
    </body>
    </html>
    Wow, you're up very early ;)

    How would this look in razor ???

    Regards,
    Holger

    PS: The question, why the errormessage doesn't get updated, still remains. I added some screenshots
    1. Startscreen
    2. I entered a wrong value
    3. Popup with values -> doubleclick and setting values with directevent
    4. errormessage still there .......Click image for larger version. 

Name:	1.JPG 
Views:	52 
Size:	99.1 KB 
ID:	5232Click image for larger version. 

Name:	2.jpg 
Views:	58 
Size:	81.3 KB 
ID:	5233Click image for larger version. 

Name:	3.JPG 
Views:	58 
Size:	75.4 KB 
ID:	5234Click image for larger version. 

Name:	4.jpg 
Views:	50 
Size:	81.2 KB 
ID:	5235
    Last edited by zwf; Dec 04, 2012 at 8:34 AM.
  8. #8
    Quote Originally Posted by zwf View Post
    Wow, you're up very early ;)
    Not too early:)

    Quote Originally Posted by zwf View Post
    How would this look in razor ???
    You can call the performRemoteValidation in the DirectEvent's Success handler.

    Quote Originally Posted by zwf View Post
    PS: The question, why the errormessage doesn't get updated, still remains. I added some screenshots
    1. Startscreen
    2. I entered a wrong value
    3. Popup with values -> doubleclick and setting values with directevent
    4. errormessage still there .......Click image for larger version. 

Name:	1.JPG 
Views:	52 
Size:	99.1 KB 
ID:	5232Click image for larger version. 

Name:	2.jpg 
Views:	58 
Size:	81.3 KB 
ID:	5233Click image for larger version. 

Name:	3.JPG 
Views:	58 
Size:	75.4 KB 
ID:	5234Click image for larger version. 

Name:	4.jpg 
Views:	50 
Size:	81.2 KB 
ID:	5235
    Could you provide a sample to reproduce?

Similar Threads

  1. Replies: 1
    Last Post: Jul 02, 2012, 10:00 AM
  2. Replies: 6
    Last Post: Aug 01, 2011, 4:53 PM
  3. Replies: 1
    Last Post: Jun 18, 2011, 10:40 AM
  4. Replies: 6
    Last Post: Oct 13, 2010, 10:26 AM
  5. Replies: 0
    Last Post: Jun 29, 2009, 8:41 PM

Posting Permissions