I am leanring to code as much as possible to aim to move into making a career out of programming/software development.
I am 42 years old so hopefully not to old to move careers but I love to learn so hopefully it will still gain me knowledge and new skills regardless.
Currently I work as engineer designer using SolidWorks to create press tooling and anodising plant drawings. Part of this role it also doing the internal IT support.
Learning to code to improve workflow at my current workplace for SolidWorks design, web apps to help with internal issues such a maintenance application and projects app.
Part of seriesBlazor
Creating this post so I can remember how to do this.
Picked this up from youtube from the blazor power hour:
This basically creates a check box which has a nice border and a tick mark in the top left which I have made look like:
@typeparam TItem
<div class="container">
@foreach (var item in Items)
{
var Id = Guid.NewGuid();
<label for="@Id" class="option_item"><!-- Check to see if the checkbox needs to be checked or not from the user data byt checking if any of the items are already in the SelectedList -->
@if (SelectedItems.Contains(item))
{
<input id="@Id"type="checkbox" class="checkbox" checked @onchange="_ => HandleChange(item)"/>var i =5;
}
else
{
<input id="@Id"type="checkbox" class="checkbox" @onchange="_ => HandleChange(item)"/>var ii =6;
}
<div class="option_inner theme"><div class="tickmark"></div><div class="name">
@ItemTemplate(item)
</div></div></label>
}
</div>
@code {
[Parameter]
public IEnumerable<TItem> Items { get; set; }
[Parameter]
public RenderFragment<TItem> ItemTemplate { get; set; }
[Parameter]
public List<TItem> SelectedItems { get; set; } =new();
[Parameter]
public EventCallback<List<TItem>> SelectedItemsChanged { get; set; }
void HandleChange(TItem item)
{
if (SelectedItems.Contains(item))
{
SelectedItems.Remove(item);
}
else
{
SelectedItems.Add(item);
}
SelectedItemsChanged.InvokeAsync(SelectedItems);
}
}
The checking if an item already exists in the selected items list is done so that if it is then the box will be checked etc.
The implementation into a blazor page for my use is: