Controllo TextArea
Il controllo TextArea permette di inserire un testo lungo. Eventuali tag Html vengono rimossi.
Personalizzazione
È possibile aggiungere delle regole di validazione associando una classe custom al controllo tramite il campo CustomControlClass.
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) : TextArea(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;
}
}
}