Skip to content

Commit

Permalink
Merge pull request #1625 from riganti/fix/auto-ui-nre-getpropertiesto…
Browse files Browse the repository at this point in the history
…display

Fix NRE in `AutoFormBase` when using FieldTemplates
  • Loading branch information
acizmarik committed Mar 29, 2023
2 parents cf7304f + 37789e2 commit 0fef041
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 21 deletions.
8 changes: 3 additions & 5 deletions src/AutoUI/Core/Controls/AutoFormBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ internal static PropertyDisplayMetadata[] GetPropertiesToDisplay(AutoUIContext c
}

var localProperties = props.Property.Select(p => MapLocalProperty(p.Key, props, context)!).ToDictionary(p => p.Name);
properties = properties.Select(p => {
var selectedProperties = properties.Select(p => {
if (localProperties.TryGetValue(p.Name, out var localProperty))
{
localProperties.Remove(p.Name);
Expand All @@ -81,10 +81,8 @@ internal static PropertyDisplayMetadata[] GetPropertiesToDisplay(AutoUIContext c
return localProperty;
}
return p;
}).Concat(
localProperties.Values
).ToArray();

}).ToArray();
properties = selectedProperties.Concat(localProperties.Values).ToArray();

if (props.IncludeProperties is { Length: > 0 })
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ public class AddressDTO
[Selection(typeof(StateSelection))]
public string State { get; set; }

[Display(GroupName = "BasicInfo")]
public DateTime? ValidFrom { get; set; }

[Display(GroupName = "ContactInfo")]
public string Email { get; set; }

Expand Down
33 changes: 27 additions & 6 deletions src/Samples/Common/Views/FeatureSamples/AutoUI/AutoForm.dothtml
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,40 @@
</head>
<body>

<h2 class="title">DynamicEntity</h2>
<h2 class="title">DynamicEntity - BulmaForm</h2>

<div class="columns">
<div class="column">
<auto:BulmaForm
DataContext="{value: Address}"
GroupName="BasicInfo"
Changed-CountryId="{staticCommand: _root.States.Items = statesDataProvider.GetSelectorItems(_root.Address).Result}">
<auto:BulmaForm DataContext="{value: Address}"
GroupName="BasicInfo"
Property-ValidFrom="{value: ValidFrom.ToBrowserLocalTime() }"
Changed-CountryId="{staticCommand: _root.States.Items = statesDataProvider.GetSelectorItems(_root.Address).Result}">
</auto:BulmaForm>
</div>
<div class="column">
<auto:BulmaForm DataContext="{value: Address}"
GroupName="ContactInfo"
GroupName="ContactInfo"
Property-Something={value: _root.Something} />

<p>
<dot:Button Text="Validate" Click="{command: null}" />
</p>
</div>
</div>

<h2 class="title">DynamicEntity - AutoForm</h2>

<div class="columns">
<div class="column">
<auto:AutoForm DataContext="{value: Address}"
GroupName="BasicInfo"
Property-ValidFrom="{value: ValidFrom.ToBrowserLocalTime() }"
Changed-CountryId="{staticCommand: _root.States.Items = statesDataProvider.GetSelectorItems(_root.Address).Result}">
</auto:AutoForm>
</div>
<div class="column">
<auto:AutoForm DataContext="{value: Address}"
GroupName="ContactInfo"
Property-Something={value: _root.Something} />

<p>
Expand Down
20 changes: 10 additions & 10 deletions src/Samples/Tests/Tests/Feature/AutoUITests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,27 +87,27 @@ public void Feature_AutoUI_AutoForm()
browser.NavigateToUrl(SamplesRouteUrls.FeatureSamples_AutoUI_AutoForm);
// selection hiding and showing
var stateField = browser.Single("#State__input");
var stateField = browser.First("#State__input");
AssertUI.IsDisplayed(stateField);
var countryField = browser.Single("#CountryId__input");
var countryField = browser.First("#CountryId__input");
countryField.Select("2");
stateField = browser.Single("#State__input");
stateField = browser.First("#State__input");
AssertUI.IsNotDisplayed(stateField);
// validation
var nameField = browser.Single("#Name__input");
var streetField = browser.Single("#Name__input");
var nameField = browser.First("#Name__input");
var streetField = browser.First("#Name__input");
AssertUI.IsNotDisplayed(nameField.ParentElement.ParentElement.Single(".help"));
AssertUI.IsNotDisplayed(streetField.ParentElement.ParentElement.Single(".help"));
AssertUI.IsNotDisplayed(nameField.ParentElement.ParentElement.First(".help"));
AssertUI.IsNotDisplayed(streetField.ParentElement.ParentElement.First(".help"));
var validateButton = browser.Single("input[type=button]");
var validateButton = browser.First("input[type=button]");
validateButton.Click();
AssertUI.IsDisplayed(nameField.ParentElement.ParentElement.Single(".help"));
AssertUI.IsDisplayed(streetField.ParentElement.ParentElement.Single(".help"));
AssertUI.IsDisplayed(nameField.ParentElement.ParentElement.First(".help"));
AssertUI.IsDisplayed(streetField.ParentElement.ParentElement.First(".help"));
});
}

Expand Down

0 comments on commit 0fef041

Please sign in to comment.