RequiredWhenAttribute class
namespace: Serenity.ComponentModel assembly: Serenity.Net.Core
Makes a field of a form required while another field has one of the values, or has a value when none are given, e.g. [RequiredWhen(nameof(Action), MyAction.OpenLink)].
[AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
public class RequiredWhenAttribute : PropertyConditionAttribute
| parameter | description |
|---|---|
| field | The name of the field whose value is checked, as the form has it, e.g. nameof(Action). |
| values | The values that make the field required, any of which the other field can have. When there are none, it is required while the other field has a value, i.e. it is not empty, and a checkbox while it is checked. |
Public Members
| name | description |
|---|---|
| RequiredWhenAttribute(…) | Makes a field of a form required while another field has one of the values, or has a value when none are given, e.g. [RequiredWhen(nameof(Action), MyAction.OpenLink)]. |
Remarks
A field that is required anyway stays required, and a field that is hidden or read only is not required. Like RequiredAttribute, it is checked by the forms only; a service can check the same with IsMet, e.g. from ToCondition.
See Also
- class PropertyConditionAttribute
- Source: RequiredWhenAttribute.cs