PDA

View Full Version : [CLOSED] RemoteValidation error remains after changing via directevent



zwf
Dec 03, 2012, 12:59 PM
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

zwf
Dec 03, 2012, 1:06 PM
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

zwf
Dec 03, 2012, 1:29 PM
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

Daniil
Dec 03, 2012, 2:35 PM
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.


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/#!/api/Ext.form.field.Base-property-inputEl

zwf
Dec 03, 2012, 3:48 PM
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

Daniil
Dec 04, 2012, 5:00 AM
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>

zwf
Dec 04, 2012, 8:24 AM
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 .......5232523352345235

Daniil
Dec 04, 2012, 12:09 PM
Wow, you're up very early ;)


Not too early:)



How would this look in razor ???


You can call the performRemoteValidation in the DirectEvent's Success handler.



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 .......5232523352345235

Could you provide a sample to reproduce?