Skip to content

Commit

Permalink
PureInput Hotfix
Browse files Browse the repository at this point in the history
I'm assuming InnerValue was to safely control the component's bound value without exposing the parent value.

Trouble is, we never properly updated this.

Rather than fix that, I opted to abuse the fact that we wrapped the bind in the first place, since TextValue only needs to be read-only and OnChange/OnInput pass it up the parent bind
  • Loading branch information
ModernMAK committed Oct 15, 2024
1 parent 863b3e9 commit de91340
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/Pure.Blazor.Components/Forms/PureInput.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Forms;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.Extensions.Logging;
using Pure.Blazor.Components.Forms.Validators;
using Pure.Blazor.Components.Primitives;

Expand All @@ -15,12 +16,21 @@ public partial class PureInput
private string defaultBorder = "border-gray-200";
private string errorBorder = "border-red-600";
private string? errorMessage;
private object? innerValue;

private string? TextValue
{
get { return innerValue?.ToString(); }
set { innerValue = value; }
get
{
return Value?.ToString();
}
set
{
// We abuse the fact that we bind Text-Value instead of Value directly.
// updates are sent via OnValue up to the actual user inputted bind
// Since we never update 'TextValue', only the getter is required to be implemented
// The compiler still requires a setter
Log.LogDebug("TextValue's `set` is not implemented; please use Value's `set`");
}
}

// the suffix needs different margins depending on labels and helper text
Expand Down Expand Up @@ -141,7 +151,6 @@ public void Validate(object? val)

protected override void OnInitialized()
{
innerValue = Value ?? default;

if (Required == true)
{
Expand Down

0 comments on commit de91340

Please sign in to comment.