Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

[RESOLVED] Problem in the form validation (AngularJS) #1644


User avatar
0
benjamim created

Even with all the fields filled keeps popping validation error

CSHTML Code

---------- START ----------------- @using Test.Noticias <div> <form name="noticiaCreateOrEditForm" role="form" novalidate class="form-validation"> <div class="modal-header"> <h4 class="modal-title"> <span ng-if="vm.noticia.id">@L("EditNoticia"): {{vm.noticia.titulo}}</span> <span ng-if="!vm.noticia.id">@L("CreateNewNoticia")</span> </h4> </div> <div class="modal-body"> <div class="form-group form-md-line-input form-md-floating-label no-hint"> <input class="form-control" type="text" name="NoticiaTitulo" ng-class="{'edited':vm.noticia.titulo}" ng-model="vm.noticia.titulo" required maxlength="@Noticia.MaxTituloLength"> <label>@L("Titulo")</label> </div> <div class="form-group form-md-line-input form-md-floating-label no-hint"> <input class="form-control" type="text" name="NoticiaDescricao" ng-class="{'edited':vm.noticia.descricao}" ng-model="vm.noticia.descricao" required /> <label>@L("Descricao")</label> </div> @enviarPush@ <div class="md-checkbox"> <input id="Setting_AllowSelfRegistration" class="md-check" type="checkbox" name="AllowSelfRegistration" ng-model="vm.noticia.enviarPush"> <label for="Setting_AllowSelfRegistration"> <span class="inc"></span> <span class="check"></span> <span class="box"></span> @L("EnviarNotificacaoPush") </label> </div> <div ng-show="vm.noticia.enviarPush" class="form-group form-md-line-input form-md-floating-label no-hint"> <input class="form-control" type="text" name="TituloPush" ng-class="{'edited':vm.noticia.tituloPush}" ng-model="vm.noticia.tituloPush" /> <label>@L("TituloPush")</label> </div> <div ng-show="vm.noticia.enviarPush" class="form-group form-md-line-input form-md-floating-label no-hint"> <input class="form-control" type="text" name="DescricaoPush" ng-class="{'edited':vm.noticia.descricaoPush}" ng-model="vm.noticia.descricaoPush" /> <label>@L("DescricaoPush")</label> </div> <div class="form-group form-md-line-input form-md-floating-label no-hint"> <input class="form-control" type="text" name="Texto" ng-class="{'edited':vm.noticia.texto}" ng-model="vm.noticia.texto" /> <label>@L("Texto")</label> </div> </div> <div class="modal-footer"> <button ng-disabled="vm.saving" type="button" class="btn btn-default" ng-click="vm.cancel()">@L("Cancel")</button> <button type="submit" button-busy="vm.saving" busy-text="@L("SavingWithThreeDot")" class="btn btn-primary blue" ng-click="vm.save()" ng-disabled="noticiaCreateOrEditForm.$invalid"><i class="fa fa-save"></i> <span>@L("Save")</span></button> </div> </form> </div> ------------END------------------

Class Dto --------- START -------------- using System.ComponentModel.DataAnnotations;

namespace Test.Noticias.Dto { public class CreateNoticiaInput { public virtual int? Id { get; set; } public virtual int TenantId { get; set; }

    [Required]
    [MaxLength(Noticia.MaxTituloLength)]
    public virtual string Titulo { get; set; }

    [Required]
    [MaxLength(Noticia.MaxDescricaoLength)]
    public virtual string Descricao { get; set; }

    [Required]
    public virtual string Texto { get; set; }

    [MaxLength(Noticia.MaxTituloPushLength)]
    public virtual string TituloPush { get; set; }

    [MaxLength(Noticia.MaxDescricaoPushLength)]
    public virtual string DescricaoPush { get; set; }

    public bool EnviarPush { get; set; }
}

}

---------END-----------


4 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Can you check json send to server via ajax request ? And share it if it is possible ?

  • User Avatar
    0
    benjamim created

    Object {id: 3, tenantId: 1, titulo: "Titulo new", descricao: "Descrição new", texto: "texto new",titulo:"Titulo new"tituloPush:"Titulo push"}

    <cite>ismcagdas: </cite> Can you check json send to server via ajax request ? And share it if it is possible ?

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Thank you for sharing your project. It helped to solve the problem.

    you should call your appService like this

    noticiaService.updateNoticia(vm.noticia)
    

    or

    noticiaService.createNoticia(vm.noticia)
    
  • User Avatar
    0
    benjamim created

    TKS A LOT!!!!