PDA

View Full Version : [CLOSED] ValidateEdit After MessageBox with focus



osef
Nov 12, 2014, 5:36 AM
Hi, I have a problem with GridPanel with CellEditing, I am validating in field ID when is blank, so, I triger a MessageBox when this is sucess, but when the MessageBox is triger I have the focus in Cell ID, so, I press the enter key the field is edit state I want the field is not editing Can you help me please?

This is the new row with the button, the field ID is blank

http://forums.ext.net/attachment.php?attachmentid=16141&stc=1

When I press the enter key with the field ID in blank, It is throw MessageBox, but I press the enter key and the field ID is editing

http://forums.ext.net/attachment.php?attachmentid=16151&stc=1



<script type="text/javascript">
//Validar la edici?n o un nuevo registro
var validateEdit_Registro = function (editor, context) {
var store = App.gpGruposMenu.getStore();

//Si el campo a validar es el ID
if (context.field == 'ID') {
//Si es vacio lanzar un error
if (context.value == '') {
Ext.Msg.show({
id: 'msgID',
title: 'Error',
msg: 'Debes capturar un ID',
buttons: Ext.MessageBox.OK,
onEsc: Ext.emptyFn,
closable: false,
icon: Ext.MessageBox.ERROR
});
}
}
};

//Insertar un nuevo registro en blanco
var click_insertarRegistro = function () {
//Get store of gridpanel
var store = App.gpGruposMenu.getStore();
//Get the total records
var total = store.getCount();

//Insert new record in the final
store.insert(total, {});
App.gpGruposMenu.getView().focusRow(total);
App.gpGruposMenu.editingPlugin.startEdit(store.get At(total), App.gpGruposMenu.columns[0]);
};
</script>

<ext:GridPanel
ID="gpGruposMenu"
runat="server"
Height="420"
Width="960"
Title="GRUPOS MEN?"
EnableColumnHide="false"
EnableColumnMove="false"
Header="true"
TitleAlign="Left">
<TopBar>
<ext:Toolbar ID="tbGruposMenu" runat="server">
<Items>
<ext:Button
ID="New"
runat="server"
Height="50"
Width="50"
Text="Nuevo">
<Listeners>
<Click Fn="click_insertarRegistro" />
</Listeners>
</ext:Button>
</Items>
</ext:Toolbar>
</TopBar>
<Store>
<ext:Store
ID="sGruposMenu"
runat="server">
<Model>
<ext:Model ID="mGruposMenu" runat="server">
<Fields>
<ext:ModelField Name="ID" Type="String" />
<ext:ModelField Name="Descripcion" Type="String" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
<ColumnModel>
<Columns>
<ext:Column
ID="cID"
runat="server"
Text="ID"
Align="Center"
Width="100"
DataIndex="ID">
<Editor>
<ext:TextField
ID="txtID"
runat="server"
MaxLength="3"
EnforceMaxLength="true">
<Listeners>
<Blur Handler="App.txtID.setValue(App.txtID.getValue().toUpperCas e());" />
</Listeners>
</ext:TextField>
</Editor>
</ext:Column>
<ext:Column
ID="cDescripcion"
runat="server"
Text="DESCRIPCI?N"
Align="Left"
Width="858"
DataIndex="Descripcion">
<Editor>
<ext:TextField
ID="txtDescripcion"
runat="server"
MaxLength="50"
EnforceMaxLength="true">
<Listeners>
<Blur Handler="App.txtDescripcion.setValue(App.txtDescripcion.get Value().toUpperCase());" />
</Listeners>
</ext:TextField>
</Editor>
</ext:Column>
</Columns>
</ColumnModel>
<View>
<ext:GridView
ID="gvGruposMenu"
runat="server"
StripeRows="true"
AllowDeselect="true">
</ext:GridView>
</View>
<Plugins>
<ext:CellEditing ID="ceGruposMenu" runat="server" ClicksToEdit="2">
<Listeners>
<ValidateEdit Fn="validateEdit_Registro" />
</Listeners>
</ext:CellEditing>
</Plugins>
<SelectionModel>
<ext:RowSelectionModel
ID="rsmGruposMenu"
runat="server"
AllowDeselect="true">
</ext:RowSelectionModel>
</SelectionModel>
</ext:GridPanel>





protected void Page_Load(object sender, EventArgs e)
{
List<GrupoMenu> lGrupoMenu = new List<GrupoMenu>();
for (int i = 0; i <= 5; i++)
{
GrupoMenu oGrupoMenu = new GrupoMenu();
oGrupoMenu.ID = "id" + i;
oGrupoMenu.Descripcion = "descripci?n" + i;
lGrupoMenu.Add(oGrupoMenu);
}

sGruposMenu.DataSource = lGrupoMenu;
sGruposMenu.DataBind();
}

public class GrupoMenu
{
public string ID
{
get;
set;
}

public string Descripcion
{
get;
set;
}
}

Daniil
Nov 12, 2014, 3:45 PM
Hi @osef,

Please try:

<ValidateEdit Fn="validateEdit_Registro" Delay="1" />

osef
Nov 12, 2014, 5:58 PM
This is working Daniil, thank you.