Feb 06, 2012, 8:06 PM
[CLOSED] Client and Server side form validation best solution
Hi.
I am a bit confused about how validation works, or the best way it has been thought to work as. I know is basic but I can't integrate all code suggestions found on forums and examples.
I need client side validation and also serverside validation (just in case user turned off Javascript) just as Microsoft's ASP.NET Validation controls do.
I saw the examples that show how to validate serverside in real time, with async remote calls, control by control, but I need a complete validation on submit event (client and server side). Returning from a failed server validation also with all warnings, icons and messages in controls such as if it had been validated client side
I am firing a save method from a button inside a Form Panel with a DirectEvent.
I can call IsValid client side from a <listener> in button, but I don't know how to suspend the direct event in case client validation fails.
Here is a dummy form with what I am telling you.
Also, how is the serverside IsValid method called? All warnings will appear if the window is re-rendered after a failed serverside IsValid call?
Thanks
Regards
Fernando
I am a bit confused about how validation works, or the best way it has been thought to work as. I know is basic but I can't integrate all code suggestions found on forums and examples.
I need client side validation and also serverside validation (just in case user turned off Javascript) just as Microsoft's ASP.NET Validation controls do.
I saw the examples that show how to validate serverside in real time, with async remote calls, control by control, but I need a complete validation on submit event (client and server side). Returning from a failed server validation also with all warnings, icons and messages in controls such as if it had been validated client side
I am firing a save method from a button inside a Form Panel with a DirectEvent.
I can call IsValid client side from a <listener> in button, but I don't know how to suspend the direct event in case client validation fails.
Here is a dummy form with what I am telling you.
<ext:FormPanel ID="FormPanel1" runat="server" Height="400" Title="Form Panel" Padding="5" MonitorResize="true">
<Items>
<ext:TextField ID="txtFirstName" runat="server" Width="150" FieldLabel="Name: " AllowBlank="false" MsgTarget="Side"/>
<ext:TextField ID="txtLastName" runat="server" Width="150" FieldLabel="LastName: " AllowBlank="false" MsgTarget="Side"/>
</Items>
<Buttons>
<ext:Button ID="btnSave" runat="server" Text="Save">
<Listeners>
<Click Handler="if (#{FormPanel1}.getForm().isValid()) {Ext.Msg.alert('HERE CANCEL SUBMIT', 'CANCELATION SHOULD BE HERE!');}else{Ext.Msg.show({icon: Ext.MessageBox.ERROR, msg: 'FormPanel is incorrect', buttons:Ext.Msg.OK});}" />
</Listeners>
<DirectEvents>
<Click OnEvent="btnSave_Click" Success="parentAutoLoadControl.close();">
<EventMask ShowMask="true" Msg="Saving..." />
</Click>
</DirectEvents>
</ext:Button>
<ext:Button ID="btnCancel" runat="server" Text="Cancel">
<Listeners>
<Click Handler="parentAutoLoadControl.close();" />
</Listeners>
</ext:Button>
</Buttons>
</ext:FormPanel>
btnSave_Click is a server side VB method that saves data. Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As DirectEventArgs)
'HERE SHOULD COME SERVER VALIDATION JUST IN CASE
Dim mPerson As New Person
mPerson .FirstName= txtFirstName.Text
mPerson .LastName= txtLastName.Text
mPerson .Save()
'IN CASE VALIDATION FAILED, THE CONTROL SHOULD BE RETURNED TO THE CLIENT WITH ALL WARNINGS ACTIVATED
End Sub
I don't know if a DirectEvent isn't the right way to do this. Should I submit all the form from clientside? That way I would condition submition to the IsValid result.Also, how is the serverside IsValid method called? All warnings will appear if the window is re-rendered after a failed serverside IsValid call?
Thanks
Regards
Fernando
Last edited by geoffrey.mcgill; Feb 13, 2012 at 9:02 PM.
Reason: [CLOSED]