Open Closed

ABP Suite Server validation errors : entity properties still required when they shouldn't be #275


User avatar
0
pkouame created

Check the docs before asking a question: https://docs.abp.io/en/commercial/latest/ Check the samples, to see the basic tasks: https://docs.abp.io/en/commercial/latest/samples/index The exact solution to your question may have been answered before, please use the search on the homepage.

  • ABP Framework version: v2.9.0
  • UI type: Angular / MVC
  • Tiered (MVC) or Identity Server Seperated (Angular): yes
  • Exception message and stack trace:
  • Steps to reproduce the issue:

in abp suite 2.9.0 - create a new entity with non-required properties (string type usually in my case) migrate and update form doesn't validate when non-required field is skipped

see below. In my Vendor Entity the Phone property is tagged as non-required:

server requires validation :

Even though the create DTO seems correct :

using System;
using System.ComponentModel.DataAnnotations;

namespace Skipj.Track.Vendors
{
    public class VendorCreateDto
    {

        [Required]
        [StringLength(VendorConsts.NameMaxLength, MinimumLength = VendorConsts.NameMinLength)]
        public string Name { get; set; }

        [StringLength(VendorConsts.PhoneMaxLength, MinimumLength = VendorConsts.PhoneMinLength)]
        public string Phone { get; set; }

        [EmailAddress]
        [StringLength(VendorConsts.EmailMaxLength, MinimumLength = VendorConsts.EmailMinLength)]
        public string Email { get; set; }

        [StringLength(VendorConsts.WebsiteMaxLength, MinimumLength = VendorConsts.WebsiteMinLength)]
        public string Website { get; set; }

        [StringLength(VendorConsts.TaxIdMaxLength, MinimumLength = VendorConsts.TaxIdMinLength)]
        public string TaxId { get; set; }

        [StringLength(VendorConsts.VendorIdMaxLength, MinimumLength = VendorConsts.VendorIdMinLength)]
        public string VendorId { get; set; }

        [StringLength(VendorConsts.AltNameMaxLength, MinimumLength = VendorConsts.AltNameMinLength)]
        public string AltName { get; set; }

        [StringLength(VendorConsts.DbaNameMaxLength, MinimumLength = VendorConsts.DbaNameMinLength)]
        public string DbaName { get; set; }

        [StringLength(VendorConsts.NotesMaxLength, MinimumLength = VendorConsts.NotesMinLength)]
        public string Notes { get; set; }

        [Required]
        public bool IsPrime { get; set; }

        [Required]
        public bool IsMdBased { get; set; }

        public bool IsWomanOwned { get; set; }

        [StringLength(VendorConsts.RatingMaxLength, MinimumLength = VendorConsts.RatingMinLength)]
        public string Rating { get; set; }

        [StringLength(VendorConsts.DisplayNameMaxLength, MinimumLength = VendorConsts.DisplayNameMinLength)]
        public string DisplayName { get; set; }

        public bool HasMdEmployees { get; set; }

        [StringLength(VendorConsts.DunsNumberMaxLength, MinimumLength = VendorConsts.DunsNumberMinLength)]
        public string DunsNumber { get; set; }

    }
}

the angular input form doesn't mark anything as required either :

    <ng-template #abpBody>
        <form [formGroup]="form" (ngSubmit)="save()" validateOnSubmit>
            <div class="mt-2 fade-in-top">
                    <div class="form-group">
      <label for="vendor-name">
          {{ '::Name' | abpLocalization }}
      </label>

      <input type="text" 
             id="vendor-name" 
             class="form-control" 			 
             formControlName="name" autofocus maxlength="64" minlength="1"/>
    </div>
    <div class="form-group">
      <label for="vendor-phone">
          {{ '::Phone' | abpLocalization }}
      </label>

      <input type="text" 
             id="vendor-phone" 
             class="form-control" 			 
             formControlName="phone"  maxlength="50" minlength="1"/>
    </div>
    <div class="form-group">
      <label for="vendor-email">
          {{ '::Email' | abpLocalization }}
      </label>

      <input type="text" 
             id="vendor-email" 
             class="form-control" 			 
             formControlName="email"  maxlength="32" minlength="1"/>
    </div>
    <div class="form-group">
      <label for="vendor-website">
          {{ '::Website' | abpLocalization }}
      </label>

      <input type="text" 
             id="vendor-website" 
             class="form-control" 			 
             formControlName="website"  maxlength="64" minlength="1"/>
    </div>
    <div class="form-group">
      <label for="vendor-taxId">
          {{ '::TaxId' | abpLocalization }}
      </label>

      <input type="text" 
             id="vendor-taxId" 
             class="form-control" 			 
             formControlName="taxId"  maxlength="10" minlength="1"/>
    </div>
    <div class="form-group">
      <label for="vendor-vendorId">
          {{ '::VendorId' | abpLocalization }}
      </label>

      <input type="text" 
             id="vendor-vendorId" 
             class="form-control" 			 
             formControlName="vendorId"  maxlength="255" minlength="1"/>
    </div>
    <div class="form-group">
      <label for="vendor-altName">
          {{ '::AltName' | abpLocalization }}
      </label>

      <input type="text" 
             id="vendor-altName" 
             class="form-control" 			 
             formControlName="altName"  maxlength="64" minlength="1"/>
    </div>
    <div class="form-group">
      <label for="vendor-dbaName">
          {{ '::DbaName' | abpLocalization }}
      </label>

      <input type="text" 
             id="vendor-dbaName" 
             class="form-control" 			 
             formControlName="dbaName"  maxlength="64" minlength="1"/>
    </div>
    <div class="form-group">
      <label for="vendor-notes">
          {{ '::Notes' | abpLocalization }}
      </label>

      <input type="text" 
             id="vendor-notes" 
             class="form-control" 			 
             formControlName="notes"  maxlength="255" minlength="1"/>
    </div>
	<div class="form-group form-check custom-checkbox custom-control">
      <input type="checkbox" 
             id="vendor-isPrime" 
             class="form-check-input custom-control-input" 
             formControlName="isPrime" />

      <label class="custom-control-label" 
             for="vendor-isPrime">
          {{ '::IsPrime' | abpLocalization }}
      </label>
    </div>
	<div class="form-group form-check custom-checkbox custom-control">
      <input type="checkbox" 
             id="vendor-isMdBased" 
             class="form-check-input custom-control-input" 
             formControlName="isMdBased" />

      <label class="custom-control-label" 
             for="vendor-isMdBased">
          {{ '::IsMdBased' | abpLocalization }}
      </label>
    </div>
	<div class="form-group form-check custom-checkbox custom-control">
      <input type="checkbox" 
             id="vendor-isWomanOwned" 
             class="form-check-input custom-control-input" 
             formControlName="isWomanOwned" />

      <label class="custom-control-label" 
             for="vendor-isWomanOwned">
          {{ '::IsWomanOwned' | abpLocalization }}
      </label>
    </div>
    <div class="form-group">
      <label for="vendor-rating">
          {{ '::Rating' | abpLocalization }}
      </label>

      <input type="text" 
             id="vendor-rating" 
             class="form-control" 			 
             formControlName="rating"  maxlength="32" minlength="1"/>
    </div>
    <div class="form-group">
      <label for="vendor-displayName">
          {{ '::DisplayName' | abpLocalization }}
      </label>

      <input type="text" 
             id="vendor-displayName" 
             class="form-control" 			 
             formControlName="displayName"  maxlength="64" minlength="1"/>
    </div>
	<div class="form-group form-check custom-checkbox custom-control">
      <input type="checkbox" 
             id="vendor-hasMdEmployees" 
             class="form-check-input custom-control-input" 
             formControlName="hasMdEmployees" />

      <label class="custom-control-label" 
             for="vendor-hasMdEmployees">
          {{ '::HasMdEmployees' | abpLocalization }}
      </label>
    </div>
    <div class="form-group">
      <label for="vendor-dunsNumber">
          {{ '::DunsNumber' | abpLocalization }}
      </label>

      <input type="text" 
             id="vendor-dunsNumber" 
             class="form-control" 			 
             formControlName="dunsNumber"  maxlength="10" minlength="1"/>
    </div>
 
            </div>
        </form>
    </ng-template>
  

**SECOND question while I'm at it : why aren't required fields tagged as such on the angular form (like red dot or asterisk on the MV forms) **


2 Answer(s)
  • User Avatar
    0
    pkouame created

    Any news on this case?

  • User Avatar
    0
    alper created
    Support Team Director

    this is expected behaviour. the phone field is not marked as required but you set min max length. so user can leave this field empty, but if any value is entered, it must be with min 1, max 50 characters.

Made with ❤️ on ABP v9.1.0-preview. Updated on December 13, 2024, 06:09