Open nickl-martin opened 8 months ago
Probably the items colletion is not null, it's an empty collection. You probably need to create a validation something like that:
public class CollectionNotEmptyValidation : IValidation
{
public string Message { get; set; }
public bool Validate(object value)
{
if (value is ICollection<object> collection)
{
return collection.Count > 0;
}
return false;
}
}
And use it like this:
<material:MultiplePickerField Title="Multiple Picker">
<material:MultiplePickerField.Validations>
<root:CollectionNotEmptyValidation Message="At least one option must be selected." />
</material:MultiplePickerField.Validations>
</material:MultiplePickerField>
I'll consider handling collections in RequiredValidation in the library in the next version
I see. Having RequiredValidation check for empty collections would be useful, however that is only part of the problem.
I dug a little deeper and found the real issue. MultiplePickerField does not override the GetValueForValidator()
virtual method defined on InputField. Because of this it uses the implementation in InputField which just returns new object()
(see below).
https://github.com/enisn/UraniumUI/blob/45858514387014504eb82f1ed90ceae5846a9a9e/src/UraniumUI.Material/Controls/InputField.Validation.cs#L97
This could be resolved with the following code added to MultiplePickerField.
protected override object GetValueForValidator()
{
return SelectedItems;
}
MultiplePickerField does not have any error text or icon when validations are applied.
Consider the following layout:
When the submit button is pressed without filling out either field it only shows the error for the single picker field.