Skip to content

Commit

Permalink
feat(blazor): no need to pass form into blockly form
Browse files Browse the repository at this point in the history
  • Loading branch information
SonicGD committed Sep 23, 2021
1 parent 29b295c commit 5694056
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 20 deletions.
4 changes: 2 additions & 2 deletions apps/Sitko.Blockly.Demo/Pages/PostFormComponent.razor
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
<FormItem Label="Title">
<Input @bind-Value="context.Entity.Title"/>
</FormItem>
<AntBlocklyForm Label="Blocks" TEntity="Post" TForm="PostForm" @bind-Value="context.Entity.Blocks" Form="context" Options="blocksOptions"></AntBlocklyForm>
<AntBlocklyForm Label="Secondary blocks" TEntity="Post" TForm="PostForm" @bind-Value="context.Entity.SecondaryBlocks" Form="context" Options="secondaryBlocksOptions"></AntBlocklyForm>
<AntBlocklyForm Label="Blocks" @bind-Value="context.Entity.Blocks" Options="blocksOptions"></AntBlocklyForm>
<AntBlocklyForm Label="Secondary blocks" @bind-Value="context.Entity.SecondaryBlocks" Options="secondaryBlocksOptions"></AntBlocklyForm>
<Button Disabled="@(!context.CanSave())" OnClick="context.Save">Save</Button>
</PostForm>

Expand Down
4 changes: 1 addition & 3 deletions src/Sitko.Blockly.AntDesign/Forms/AntBlocklyForm.razor
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
@typeparam TEntity
@typeparam TForm
@inherits Sitko.Blockly.Blazor.Forms.BlocklyForm<TEntity, TForm, AntDesignBlocklyFormOptions>
@inherits Sitko.Blockly.Blazor.Forms.BlocklyForm<AntDesignBlocklyFormOptions>
<div class="blockly-form [email protected]().ToLowerInvariant()">
@if (!string.IsNullOrEmpty(Label))
{
Expand Down
7 changes: 2 additions & 5 deletions src/Sitko.Blockly.AntDesign/Forms/AntBlocklyForm.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@
namespace Sitko.Blockly.AntDesignComponents.Forms
{
using System.Threading.Tasks;
using Sitko.Blazor.ScriptInjector;

public partial class AntBlocklyForm<TEntity, TForm> where TEntity : class, new()
where TForm : Sitko.Core.App.Blazor.Forms.BaseForm<TEntity>
public partial class AntBlocklyForm
{
[Inject]
protected ILocalizationProvider<AntBlocklyForm<TEntity, TForm>> LocalizationProvider { get; set; } = null!;
[Inject] protected ILocalizationProvider<AntBlocklyForm> LocalizationProvider { get; set; } = null!;

[Inject] protected IOptions<AntDesignBlocklyModuleOptions> ModuleOptions { get; set; } = null!;

Expand Down
12 changes: 2 additions & 10 deletions src/Sitko.Blockly.Blazor/Forms/BlocklyForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Forms;
using Microsoft.JSInterop;
using Sitko.Core.App.Blazor.Forms;
using Sitko.Core.App.Collections;

namespace Sitko.Blockly.Blazor.Forms
Expand All @@ -19,17 +18,10 @@ public interface IBlocklyForm
void ValidateBlocks();
}

public abstract class BlocklyForm<TEntity, TForm, TOptions> : InputBase<List<ContentBlock>>, IBlocklyForm
where TForm : BaseForm<TEntity>
where TEntity : class, new()
public abstract class BlocklyForm<TOptions> : InputBase<List<ContentBlock>>, IBlocklyForm
where TOptions : BlazorBlocklyFormOptions, new()
{
private ContentBlock? blockToScroll;
#if NET6_0_OR_GREATER
[EditorRequired]
#endif
[Parameter]
public TForm Form { get; set; } = null!;

protected Dictionary<Guid, BlockForm> BlockForms { get; } = new();

Expand Down Expand Up @@ -158,7 +150,7 @@ private void ValidateBlock(ContentBlock block)
{
foreach (var property in block.GetType().GetProperties())
{
Form.NotifyChange(new FieldIdentifier(block, property.Name));
EditContext.NotifyFieldChanged(new FieldIdentifier(block, property.Name));
}
}

Expand Down

0 comments on commit 5694056

Please sign in to comment.