Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Form validation blazor within a fluentdatagrid

$
0
0

I have a class with lets say two properties, 'active' and 'username'

And a grid displaying the values like so:

<FluentDataGrid Items="@sortedModal" Titem="ExceptionalUseIgnoreUser" Pagination="@pagination"><!-- Actions Column --><TemplateColumn Title="Actions" Width="110px"><CellTemplate Context="context">            @if (context.IsEditing)            {<div><button class="slikaButton" style="width:40px;" @onclick="(() => Cancel(context))">Cancel</button><button class="slikaButton" style="width:40px;" @onclick="(() => Save(context))">Save</button></div>            }            else            {<button class="slikaButton" style="width:40px;" @onclick="(() => Edit(context))">Edit</button>            }</CellTemplate></TemplateColumn><!-- UserName Column --><TemplateColumn Title="User" Sortable="true"><CellTemplate Context="context">            @if (context.IsEditing)            {<input type="text" @bind="context.UserName" style="width: 100%;" />            }            else            {                @context.UserName            }</CellTemplate></TemplateColumn><!-- Active Column (Dropdown) --><TemplateColumn Title="active" Sortable="true" Width="120px"><CellTemplate Context="context">           @if (context.IsEditing)           {<select @bind="context.Active" style="width:100%; border: 1px solid;">                   @foreach (var option in dropDownActiveOptions)                   {<option value="@option.Key">@option.Value</option>                   }</select>           }           else           {               @context.Active           }</CellTemplate></TemplateColumn>

Ive been trying for a long while to understand how to display the data annotation of my class, for example

[Required(ErrorMessage ="active is required")]public string Active{ get; set; }

When adding row to the fluentdatagrid,I add a new empty row to my modal

        List<ExceptionalUseIgnoreUser> modal = new List<ExceptionalUseIgnoreUser>();        IQueryable<ExceptionalUseIgnoreUser> sortedModal;private void AddNewRow(){ var newRow = new ExceptionalUseIgnoreUser();     StateHasChanged(); modal.Insert(0, newRow); // Inserts the new row at the beginning of the list sortedModal = modal.AsQueryable(); // Updates the grid's data}

so what will happen is that my table will have a new row on top of it with matching elements as of for the edit mode.

Now, as you can see, above I have Edit button which splits into Cancel and save once clicked.So basically my goal is when clicking save button, to validate the form and for that specific column, in my example the active column, to display the validationmessage.

Ive been trying many solutions, I keep getting the error

Severity    Code    Description Project File    Line    Suppression StateError   RZ9999  The child content element 'ChildContent' of component 'EditForm' uses the same parameter name ('context') as enclosing child content element 'ChildContent' of component 'TemplateColumn'. Specify the parameter name like: '<ChildContent Context="another_name"> to resolve the ambiguity MasterAdmin C:\Users\gal\Desktop\SlikaNetCoreRelated\SlikaNetCore\MasterAdmin\CSC   1   

Ive been trying to change names but it seems like im in a forever loop.Help would be much appreciated.THANKS!


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>