Skip to content

Commit

Permalink
CRUD validation messages at field level (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavnavar committed May 27, 2020
1 parent 2920330 commit 56d9017
Show file tree
Hide file tree
Showing 22 changed files with 262 additions and 45 deletions.
2 changes: 1 addition & 1 deletion GridBlazor/GridBlazor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<LangVersion>8.0</LangVersion>
<GenerateEmbeddedFilesManifest>True</GenerateEmbeddedFilesManifest>
<EnableDefaultEmbeddedResourceItems>False</EnableDefaultEmbeddedResourceItems>
<Version>1.6.5</Version>
<Version>1.6.6</Version>
<Title>GridBlazor</Title>
<Description>Grid components for Blazor</Description>
<Summary>Grid components for Blazor</Summary>
Expand Down
27 changes: 15 additions & 12 deletions GridBlazor/Pages/GridCreateComponent.razor
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
}
else if (type == typeof(string) && ((IGridColumn<T>)column).InputType == InputType.TextArea)
{
<textarea id="@column.FieldName" name="@column.FieldName" class="form-control" rows="5" value="@column.GetFormatedValue(value)" @onchange="(e) => ChangeValue(e, column)" />
<textarea id="@column.FieldName" name="@column.FieldName" class="form-control @(ColumnErrors.ContainsKey(@column.FieldName) ? "input-validation-error" : "")" rows="5" value="@column.GetFormatedValue(value)" @onchange="(e) => ChangeValue(e, column)" />
}
else if (type == typeof(DateTime) || type == typeof(System.DateTimeOffset))
{
Expand All @@ -67,60 +67,63 @@
{
if (GridComponent._isWeekSupported)
{
<input id="@column.FieldName" name="@column.FieldName" type="@typeAttr" placeholder="yyyy-Www" class="form-control" value="@(((ICGridColumn)column).GetFormatedDateTime(value, typeAttr))" @onchange="(e) => ChangeValue(e, column, typeAttr)" />
<input id="@column.FieldName" name="@column.FieldName" type="@typeAttr" placeholder="yyyy-Www" class="form-control @(ColumnErrors.ContainsKey(@column.FieldName) ? "input-validation-error" : "")" value="@(((ICGridColumn)column).GetFormatedDateTime(value, typeAttr))" @onchange="(e) => ChangeValue(e, column, typeAttr)" />
}
else
{
<input id="@column.FieldName" name="@column.FieldName" type="text" placeholder="yyyy-Www" class="form-control" value="@(((ICGridColumn)column).GetFormatedDateTime(value, typeAttr))" @onchange="(e) => ChangeValue(e, column, typeAttr)" />
<input id="@column.FieldName" name="@column.FieldName" type="text" placeholder="yyyy-Www" class="form-control @(ColumnErrors.ContainsKey(@column.FieldName) ? "input-validation-error" : "")" value="@(((ICGridColumn)column).GetFormatedDateTime(value, typeAttr))" @onchange="(e) => ChangeValue(e, column, typeAttr)" />
}
}
else if (typeAttr == "month")
{
if (GridComponent._isMonthSupported)
{
<input id="@column.FieldName" name="@column.FieldName" type="@typeAttr" placeholder="yyyy-mm" class="form-control" value="@(((ICGridColumn)column).GetFormatedDateTime(value, typeAttr))" @onchange="(e) => ChangeValue(e, column, typeAttr)" />
<input id="@column.FieldName" name="@column.FieldName" type="@typeAttr" placeholder="yyyy-mm" class="form-control @(ColumnErrors.ContainsKey(@column.FieldName) ? "input-validation-error" : "")" value="@(((ICGridColumn)column).GetFormatedDateTime(value, typeAttr))" @onchange="(e) => ChangeValue(e, column, typeAttr)" />
}
else
{
<input id="@column.FieldName" name="@column.FieldName" type="text" placeholder="yyyy-mm" class="form-control" value="@(((ICGridColumn)column).GetFormatedDateTime(value, typeAttr))" @onchange="(e) => ChangeValue(e, column, typeAttr)" />
<input id="@column.FieldName" name="@column.FieldName" type="text" placeholder="yyyy-mm" class="form-control @(ColumnErrors.ContainsKey(@column.FieldName) ? "input-validation-error" : "")" value="@(((ICGridColumn)column).GetFormatedDateTime(value, typeAttr))" @onchange="(e) => ChangeValue(e, column, typeAttr)" />
}
}
else if (typeAttr == "datetime-local")
{
if (GridComponent._isDateTimeLocalSupported)
{
<input id="@column.FieldName" name="@column.FieldName" type="@typeAttr" placeholder="yyyy-mm-dd hh:mm" class="form-control" value="@(((ICGridColumn)column).GetFormatedDateTime(value, typeAttr))" @onchange="(e) => ChangeValue(e, column, typeAttr)" />
<input id="@column.FieldName" name="@column.FieldName" type="@typeAttr" placeholder="yyyy-mm-dd hh:mm" class="form-control @(ColumnErrors.ContainsKey(@column.FieldName) ? "input-validation-error" : "")" value="@(((ICGridColumn)column).GetFormatedDateTime(value, typeAttr))" @onchange="(e) => ChangeValue(e, column, typeAttr)" />
}
else
{
<input id="@column.FieldName" name="@column.FieldName" type="text" placeholder="yyyy-mm-dd hh:mm" class="form-control" value="@(((ICGridColumn)column).GetFormatedDateTime(value, typeAttr))" @onchange="(e) => ChangeValue(e, column, typeAttr)" />
<input id="@column.FieldName" name="@column.FieldName" type="text" placeholder="yyyy-mm-dd hh:mm" class="form-control @(ColumnErrors.ContainsKey(@column.FieldName) ? "input-validation-error" : "")" value="@(((ICGridColumn)column).GetFormatedDateTime(value, typeAttr))" @onchange="(e) => ChangeValue(e, column, typeAttr)" />
}
}
else
{
<input id="@column.FieldName" name="@column.FieldName" type="@typeAttr" class="form-control" value="@(((ICGridColumn)column).GetFormatedDateTime(value, typeAttr))" @onchange="(e) => ChangeValue(e, column, typeAttr)" />
<input id="@column.FieldName" name="@column.FieldName" type="@typeAttr" class="form-control @(ColumnErrors.ContainsKey(@column.FieldName) ? "input-validation-error" : "")" value="@(((ICGridColumn)column).GetFormatedDateTime(value, typeAttr))" @onchange="(e) => ChangeValue(e, column, typeAttr)" />
}
}
else if (type == typeof(System.TimeSpan))
{
string typeAttr = ((IGridColumn<T>)column).InputType == InputType.None ? "time" : ((IGridColumn<T>)column).InputType.ToTypeAttr();
<input id="@column.FieldName" name="@column.FieldName" type="@typeAttr" class="form-control" value="@(((ICGridColumn)column).GetFormatedDateTime(value, typeAttr))" @onchange="(e) => ChangeValue(e, column)" />
<input id="@column.FieldName" name="@column.FieldName" type="@typeAttr" class="form-control @(ColumnErrors.ContainsKey(@column.FieldName) ? "input-validation-error" : "")" value="@(((ICGridColumn)column).GetFormatedDateTime(value, typeAttr))" @onchange="(e) => ChangeValue(e, column)" />
}
else if (type == typeof(bool))
{
if (value != null && (bool)value == true)
{
<input id="@column.FieldName" name="@column.FieldName" type="checkbox" class="form-control" checked="checked" value="true" @onchange="(e) => ChangeValue(e, column)" />
<input id="@column.FieldName" name="@column.FieldName" type="checkbox" class="form-control @(ColumnErrors.ContainsKey(@column.FieldName) ? "input-validation-error" : "")" checked="checked" value="true" @onchange="(e) => ChangeValue(e, column)" />
}
else
{
<input id="@column.FieldName" name="@column.FieldName" type="checkbox" class="form-control" value="false" @onchange="(e) => ChangeValue(e, column)" />
<input id="@column.FieldName" name="@column.FieldName" type="checkbox" class="form-control @(ColumnErrors.ContainsKey(@column.FieldName) ? "input-validation-error" : "")" value="false" @onchange="(e) => ChangeValue(e, column)" />
}
}
else
{
<input id="@column.FieldName" name="@column.FieldName" class="form-control" value="@column.GetFormatedValue(value)" @onchange="(e) => ChangeValue(e, column)" />
<input id="@column.FieldName" name="@column.FieldName" class="form-control @(ColumnErrors.ContainsKey(@column.FieldName) ? "input-validation-error" : "")" value="@column.GetFormatedValue(value)" @onchange="(e) => ChangeValue(e, column)" />
}
<span class="field-validation-error">
<span>@ColumnErrors.Get(column.FieldName)</span>
</span>
}
</div>
</div>
Expand Down
3 changes: 3 additions & 0 deletions GridBlazor/Pages/GridCreateComponent.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public partial class GridCreateComponent<T> : ICustomGridComponent<T>
private IEnumerable<string> _tabGroups;

public string Error { get; set; } = "";
public QueryDictionary<string> ColumnErrors { get; set; } = new QueryDictionary<string>();

[CascadingParameter(Name = "GridComponent")]
protected GridComponent<T> GridComponent { get; set; }
Expand Down Expand Up @@ -132,6 +133,8 @@ protected async Task CreateItem()
{
try
{
Error = "";
ColumnErrors = new QueryDictionary<string>();
await GridComponent.CreateItem(this);
}
catch (GridException e)
Expand Down
Loading

0 comments on commit 56d9017

Please sign in to comment.