/// <summary> /// Check the validity of the field based on the data submitted. Note that /// this validation is performed on the wire data - i.e. that which is /// submitted, before any setFormatter is run /// </summary> /// <param name="data">Data from HTTP to check</param> /// <param name="editor">Editor instance</param> /// <returns>`null` if valid, or error message string if not valid</returns> internal string Validate(Dictionary <string, object> data, Editor editor) { if (_Validators == null) { return(null); } dynamic val = _ReadProp(Name(), data); DtRequest processData = editor.InData(); ValidationHost host = new ValidationHost() { Action = processData.Action, Id = processData.Ids.Count() > 0 ? processData.Ids[0].Replace(editor.IdPrefix(), "") : null, Field = this, Editor = editor }; foreach (var validator in _Validators) { string res = validator(val, data, host); if (res != null) { return(res); } } return(null); }
/// <summary> /// Check the validity of the field based on the data submitted. Note that /// this validation is performed on the wire data - i.e. that which is /// submitted, before any setFormatter is run /// </summary> /// <param name="data">Data from HTTP to check</param> /// <param name="editor">Editor instance</param> /// <param name="id">Row id for the row being edited</param> /// <returns>`null` if valid, or error message string if not valid</returns> internal string Validate(Dictionary <string, object> data, Editor editor, string id = null) { if (_validators == null) { return(null); } var val = _ReadProp(Name(), data); var processData = editor.InData(); var host = new ValidationHost { Action = processData.Action, Id = id, Field = this, Editor = editor, Db = editor.Db() }; foreach (var validator in _validators) { var res = validator(val, data, host); if (res != null) { return(res); } } return(null); }