PDA

View Full Version : [CLOSED] Validation



adelaney
Jun 15, 2012, 3:47 PM
I have a grid with a combo editor and a RowEditing plugin. The combo allows type-ahead. Now I am trying to validate my entry. When I just type in some letters and tab without actually selecting anything from the drop-down, the new value is that text, and not the value associated in the store (which, since it doesn't exist should be null or 0 - I would think). Also, because I am in a grid and using an "Add" button, I have inserted to the grid and have to use a cancel edit function to remove that insert if the row editor is cancelled. So, my question is how do I validate my combo and stop any other eventes without raising the cancel event on my RowEditing plug-in?

Daniil
Jun 15, 2012, 5:55 PM
Hi,

I would try to use the ComboBox Validator.
http://docs.sencha.com/ext-js/4-1/#!/api/Ext.form.field.Text-cfg-validator

Example

<%@ Page Language="C#" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
Store store = this.ComboBox1.GetStore();
store.DataSource = new object[]
{
new object[] { "1", "item1" },
new object[] { "2", "item2" },
new object[] { "3", "item3" }
};
store.DataBind();
}
}
</script>

<!DOCTYPE>

<html>
<head runat="server">
<title>Ext.NET v2 Example</title>

<script type="text/javascript">
var myValidator = function (value) {
var valid = true;

if (value !== "item2") {
valid = "Must be 'item2'";
}

return valid;
};
</script>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />
<ext:ComboBox ID="ComboBox1" runat="server">
<Validator Fn="myValidator" />
<Store>
<ext:Store runat="server">
<Model>
<ext:Model runat="server">
<Fields>
<ext:ModelField Name="value" />
<ext:ModelField Name="text" />
</Fields>
</ext:Model>
</Model>
<Reader>
<ext:ArrayReader />
</Reader>
</ext:Store>
</Store>
</ext:ComboBox>
</form>
</body>
</html>