Hide
ValidateInput

Validate the input of the field when the value changes.

  • string callback is the callback function to validate the data.

    Parameters:

    1. If the function accepts no arguments, then no argument will be passed
    2. If the function accepts required arguments, the first required argument will receive the field's value. If there is another required argument and the field is inside a list/array, the index will be passed.
    3. If the function only has optional arguments, it will try to pass the field's value and index if possible, otherwise the default value of the parameter will be passed.

    Return:

    1. If return type is string, then null or empty string for valid, otherwise, the string will be used as the error message
    2. If return type is bool, then true for valid, false for invalid with message "`{label}` is invalid`"
  • AllowMultiple: Yes

using SaintsField; // string callback [ValidateInput(nameof(OnValidateInput))] public int _value; private string OnValidateInput() => _value < 0 ?
quot;Should be positive, but gets
{_value}" : null; // property validate [ValidateInput(nameof(boolValidate))] public bool boolValidate; // bool callback [ValidateInput(nameof(BoolCallbackValidate))] public string boolCallbackValidate; private bool BoolCallbackValidate() => boolValidate; // with callback params [ValidateInput(nameof(ValidateWithReqParams))] public int withReqParams; private string ValidateWithReqParams(int v) =>
quot;ValidateWithReqParams:
{v}"; // with optional callback params [ValidateInput(nameof(ValidateWithOptParams))] public int withOptionalParams; private string ValidateWithOptParams(string sth="a", int v=0) =>
quot;ValidateWithOptionalParams[
{sth}]: {v}"; // with array index callback [ValidateInput(nameof(ValidateValArr))] public int[] valArr; private string ValidateValArr(int v, int index) =>
quot;ValidateValArr[
{index}]: {v}";