TextBox Control

The TextBox control allows you to enter short text. Any Html tags are removed.
 
 
Personalization
You can add validation rules by associating a custom class with the control via the CustomControlClass field.
 
using System;
using System.Linq;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using DataWeb.Structure;
using DataWeb.Validation;
using DataWeb.Identity;
using Microsoft.Extensions.Localization;
using System.Threading;

namespace DataWeb.Data.Controls
{
    public class Area_Name(Form form, IServiceProvider serviceProvider) : TextBox(form, serviceProvider)
    {
        private readonly IStructureService structureService = serviceProvider.GetService<IStructureService>();
        private readonly IStringLocalizer localizer = serviceProvider.GetService<IStringLocalizer>();

        public override async Task<List<ValidationError>>ValidateAsync(object value, List<Form.ProvidedValue> providedValues, Dictionary<string, object> sectionData, IUser user, string itemId = null, NavigationContext navigationContext = null, CancellationToken cancellationToken = default)
        {
            var errors = await base.ValidateAsync(value, providedValues, sectionData, user, itemId, navigationContext, cancellationToken);

            var areas = await structureService.GetAllAreasAsync(cancellationToken);
            if (areas.Any(x => x.Name.Equals(Convert.ToString(value), StringComparison.OrdinalIgnoreCase) && x.IdMaster != navigationContext.Navigation.Current.IdMaster))
            {
                errors.Add(new ValidationError { Name = "Name", Message = localizer["DataWeb.Form.Control_NameAlreadyExists"] });
            }

            return errors;
        }
    }
}