[CLOSED] Validate FormPanel and Save It using DirectMethods using MVC

Page 1 of 2 12 LastLast
  1. #1

    [CLOSED] Validate FormPanel and Save It using DirectMethods using MVC

    Hi,

    I have the piece of code below and I want to Save the form using Direct Methods and MVC but I try many samples and nothing seems to work. Could you help me? Please provide and MVC sample on how to save forms and validate it both on client and server side.
    Another thing, can I update the Status bar from serve side instead of using Ext.Msg.Show() as I'm using in my controller? If yes, How can I do that.

    I notices that there are many examples using Web Forms and just a few using MVC. Even the examples page is much more complete for web forms than for MVC. Is there any good source of material for MVC Ext.NET aside from https://examples2.ext.net/ ?
    Thank you very much

    Here's the code:

    x.Panel()
                .Title("Dados Paciente")
                .AutoScroll(true)
                .Border(false)
                .Items(
                    x.FormPanel()
                        .ID("frmPaciente")
                        .Border(false)
                        .Layout(LayoutType.Fit)
                        .FieldDefaults(fd =>
                            {
                                fd.LabelAlign = LabelAlign.Left;
                                fd.MsgTarget = MessageTarget.Side;
                                fd.InvalidText = "Obrigat?rio";
                                fd.EnforceMaxLength = true;
                                fd.AutoFitErrors = true;
                                //fd.AllowBlank = false;
                                fd.SelectOnFocus = true;
                                fd.LabelWidth = 150;
                            })
                        .ItemsFromPartial("_DadosPaciente", Model.PacienteModel)
                )
                .Buttons(
                    x.Button()
                        .Icon(Icon.Erase)
                        .Text("Limpar Campos")
                        .OnClientClick("this.up('frmPaciente').getForm().reset();"),
                    x.Button()
                        .Icon(Icon.DatabaseSave)
                        .Text("Pr?ximo Passo")
                        .ID("btnSave")
                        .FormBind(true)
                        .Type(ButtonType.Submit)
                        .CausesValidation(true)
                        .DirectEvents(de =>
                        {
                            de.Click.Before = "return #{frmPaciente}.getForm().isValid();";
                            de.Click.Success = "#{DirectMethods}.SavePaciente()";
                        })
                        //.OnClientClick("return #{frmPaciente}.isValid();")
                        //.DirectClickAction("Save", "Paciente")
                ).Border(true),
    Here's the controller code:
    [DirectMethod]
            public ActionResult Save(PacienteModel paciente)
            {
                X.Msg.Show(new MessageBoxConfig
                {
                    Message = "Salvando Paciente, aguarde...",
                    ProgressText = "Salvando...",
                    Width = 300,
                    Wait = true,
                    WaitConfig = new WaitConfig { Interval = 200 },
                    IconCls = "ext-mb-download",
                    AnimEl = this.GetCmp<Button>("btnSave").ClientID,
                });
    
                X.AddScript("setTimeout(function () { Ext.MessageBox.hide(); Sucesso('pnlDadosPessoais','Paciente salvo com sucesso!','Informa??o'); }, 4000);");
    
                return this.Direct();
            }
    Last edited by Daniil; Mar 19, 2014 at 8:50 AM. Reason: [CLOSED]
  2. #2
    Please provide and MVC sample on how to save forms and validate it both on client and server side.
    Please see the following samples
    http://mvc.ext.net/#/Models/Submit/
    http://mvc.ext.net/#/Models/Data_Annotations/
    http://mvc.ext.net/#/Models/Model_State/ (online sample doesn't work (it is not updated yet) but you can run it for SVN vesrion)


    Another thing, can I update the Status bar from serve side instead of using Ext.Msg.Show() as I'm using in my controller? If yes, How can I do that.
    What Status bar do you mean? Ext.Net StatusBar? If yes then see the following sample
    https://examples2.ext.net/#/Toolbar/StatusBar/Overview/
  3. #3

    Showing errors inside the form

    Hi,

    I'm using Data Annotations as you point out and I receiving a Json as a result of validation but, How can I use this JSON as errors messages inside the form?

    Click image for larger version. 

Name:	2014-03-10_1713.png 
Views:	40 
Size:	87.7 KB 
ID:	7921

    Here's the code Now:

    public class PacienteModel : IValidatableObject
        {
            public long Id { get; set; }
            public List<Ext.Net.ListItem> PacientesTipos { get; set; }
            public List<Ext.Net.ListItem> Etnias { get; set; }
            public List<Ext.Net.ListItem> TiposSanguineos { get; set; }
            public List<Ext.Net.ListItem> EstadosCivis { get; set; }
            public List<ESTADOS> Estados { get; set; }
            public List<CIDADES> Cidades { get; set; }
            public List<Ext.Net.ListItem> FormasPagtos { get; set; }
    
            [Required(ErrorMessage = "Nome Obrigat?rio")]
            public string NomePaciente { get; set; }
    
            [Required(ErrorMessage = "Email Obrigat?rio")]
            public string EmailPaciente { get; set; }
    
            [Required(ErrorMessage = "Data de Nascimento Obrigat?ria")]
            public DateTime DataNascimento { get; set; }
    
            [Required(ErrorMessage="Idade Obrigat?ria")]
            public int Idade { get; set; }
            public int QtdFilhos { get; set; }
    
            [Required(ErrorMessage="Por favor, selecione um tipo de paciente")]
            public int PacienteTipoId { get; set; }
            
            [Required(ErrorMessage="Por favor, selecione uma etnia para o paciente")]
            public int EtniaId { get; set; }
            
            [Required(ErrorMessage="Por favor, selecione um Tipo Sangu?neo")]
            public int TipoSanguineoId { get; set; }
    
            [Required(ErrorMessage="Por favor, selecione um Estado Civil")]
            public int EstadoCivilId { get; set; }
    
            [Required(ErrorMessage="Por favor, selecione um Estado")]
            public int EstadoId { get; set; }
    
            [Required(ErrorMessage="Por favor, selecione uma Cidade")]
            public int CidadeId { get; set; }
    
            public int FormaPagtoId { get; set; }
    
            [Required(ErrorMessage = "Endere?o Obrigat?rio")]
            public string Endereco { get; set; }
           
            [Required(ErrorMessage = "N?mero Obrigat?rio")]
            public string Numero { get; set; }
           
            public string Complemento { get; set; }
    
            [Required(ErrorMessage = "Bairro Obrigat?rio")]
            public string Bairro { get; set; }
    
            [Required(ErrorMessage = "Cep Obrigat?rio")]
            [MinLength(8)]
            [MaxLength(9)]
            public string Cep { get; set; }
    
            public PacienteModel()
            {
                Id = 0;
                PacientesTipos = new List<Ext.Net.ListItem>();
                Etnias = new List<Ext.Net.ListItem>();
                TiposSanguineos = new List<Ext.Net.ListItem>();
                EstadosCivis = new List<Ext.Net.ListItem>();
                Estados = new List<ESTADOS>();
                Cidades = new List<CIDADES>();
                FormasPagtos = new List<Ext.Net.ListItem>();
                Endereco = string.Empty;
                Numero = string.Empty;
                Complemento = string.Empty;
                Bairro = string.Empty;
                Cep = string.Empty;
                NomePaciente = string.Empty;
                EmailPaciente = string.Empty;
                DataNascimento = DateTime.MinValue;
                Idade = 0;
                QtdFilhos = 0;
                PacienteTipoId = 0;
                EtniaId = 0;
                TipoSanguineoId = 0;
                EstadoCivilId = 0;
                EstadoId = 0;
                CidadeId = 0;
            }
    
            public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
            {
                yield break;
            }
    public ActionResult SavePaciente(PacienteModel paciente)
            {
                if (ModelState.IsValid)
                {
                    X.Msg.Show(new MessageBoxConfig
                    {
                        Message = "Salvando Paciente, aguarde...",
                        ProgressText = "Salvando...",
                        Width = 300,
                        Wait = true,
                        WaitConfig = new WaitConfig { Interval = 200 },
                        IconCls = "ext-mb-download",
                        AnimEl = this.GetCmp<Button>("btnSave").ClientID,
                    });
    
                    X.AddScript("setTimeout(function () { Ext.MessageBox.hide(); Sucesso('pnlDadosPessoais','Paciente salvo com sucesso!','Informa??o'); }, 2000);");
    
                }
    
                return this.FormPanel(ModelState);
            }
    Last edited by Ujvari; Mar 10, 2014 at 8:21 PM.
  4. #4
    Please provide runable sample demonstrates the issue

    To use 'return this.FormPanel(ModelState);' you need to submit form instead direct event using
    Handler = "this.up('form').submit();"
    See Model State example for details
  5. #5
    The MVC Examples Explorer has been updated to the 2.5.0 release.
    Geoffrey McGill
    Founder
  6. #6

    Examples not working

    Quote Originally Posted by geoffrey.mcgill View Post
    The MVC Examples Explorer has been updated to the 2.5.0 release.

    The updated examples aren't working as showed in prints below

    Click image for larger version. 

Name:	2014-03-10_2001.png 
Views:	36 
Size:	42.7 KB 
ID:	7951

    Click image for larger version. 

Name:	2014-03-10_2000.png 
Views:	32 
Size:	10.8 KB 
ID:	7961
    Last edited by geoffrey.mcgill; Mar 10, 2014 at 11:09 PM.
  7. #7

    Not Working

    Quote Originally Posted by Vladimir View Post
    Please provide runable sample demonstrates the issue

    To use 'return this.FormPanel(ModelState);' you need to submit form instead direct event using
    Handler = "this.up('form').submit();"
    See Model State example for details
    The option provided above is not working just because it don't get to my Controller properly. I want to submit the form without using any javascript function to do it. Is that possible?
  8. #8
    Quote Originally Posted by Ujvari View Post
    The updated examples aren't working as showed in prints below
    I tested the samples linked to above, and they all appear to be functioning correctly.
    Geoffrey McGill
    Founder
  9. #9

    Still not working

    Quote Originally Posted by geoffrey.mcgill View Post
    I tested the samples linked to above, and they all appear to be functioning correctly.
    It happens when you click on Source Code.
  10. #10
    Quote Originally Posted by Ujvari View Post
    It happens when you click on Source Code.
    Thank you for the report. It has been fixed in the revision #5714 and online.
Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 3
    Last Post: Jun 11, 2013, 4:48 AM
  2. [CLOSED] How to load FormPanel data using DirectMethods
    By jchau in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Sep 18, 2012, 10:53 AM
  3. [CLOSED] Save FormPanel fields after Confirm Message
    By Digital.Dynamics in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: May 10, 2012, 6:31 AM
  4. Replies: 12
    Last Post: Feb 20, 2012, 1:58 PM
  5. Replies: 1
    Last Post: Jul 27, 2011, 10:19 AM

Tags for this Thread

Posting Permissions