Skip to content

Commit fcbeeb3

Browse files
Generate field identifiers when not in an edit context
1 parent a0224b1 commit fcbeeb3

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/Components/Web/src/Forms/InputBase.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public abstract class InputBase<TValue> : ComponentBase, IDisposable
2424
private bool _previousParsingAttemptFailed;
2525
private ValidationMessageStore? _parsingValidationMessages;
2626
private Type? _nullableUnderlyingType;
27+
private bool _shouldGenerateFieldNames;
2728

2829
[CascadingParameter] private EditContext? CascadedEditContext { get; set; }
2930

@@ -204,7 +205,7 @@ protected string NameAttributeValue
204205
return Convert.ToString(nameAttributeValue, CultureInfo.InvariantCulture) ?? string.Empty;
205206
}
206207

207-
if (EditContext?.ShouldUseFieldIdentifiers ?? false)
208+
if (_shouldGenerateFieldNames)
208209
{
209210
if (_formattedValueExpression is null && ValueExpression is not null)
210211
{
@@ -241,6 +242,12 @@ public override Task SetParametersAsync(ParameterView parameters)
241242
{
242243
EditContext = CascadedEditContext;
243244
EditContext.OnValidationStateChanged += _validationStateChangedHandler;
245+
_shouldGenerateFieldNames = EditContext.ShouldUseFieldIdentifiers;
246+
}
247+
else
248+
{
249+
// Ideally we'd know if we were in an SSR context but we don't
250+
_shouldGenerateFieldNames = !OperatingSystem.IsBrowser();
244251
}
245252

246253
_nullableUnderlyingType = Nullable.GetUnderlyingType(typeof(TValue));

0 commit comments

Comments
 (0)