protected override Control CreateValidatorControl() { InputFormRequiredFieldValidator validator = new InputFormRequiredFieldValidator { FriendlyNameOfControlToValidate = _field.Title, ID = ("vr" + _field.Name) }; if (_field.Control == ActionEditorControlsType.Date || _field.Control == ActionEditorControlsType.DateTime) { validator.ControlToValidate = _targetControl.Controls[0].ID; } else { validator.ControlToValidate = _targetControl.ID; } // TODO: Localization validator.Text = "Required!!"; validator.Display = ValidatorDisplay.Dynamic; validator.SetFocusOnError = true; return(validator); }
private void SetListFormFields(Control canvas) { List <DesignDataSource> sources = new List <DesignDataSource>(); if (!string.IsNullOrEmpty(DataSourcesData)) { sources = Utilities.DeserializeObject <List <DesignDataSource> >(DataSourcesData); } if (inEditMode) { } SPSecurity.RunWithElevatedPrivileges(delegate() { SPSite site = SPContext.Current.Site; foreach (DesignDataSource source in sources) { SPWeb web = site.OpenWeb(new Guid(source.WebId)); SPList list = web.Lists[new Guid(source.ListId)]; SPView view = list.GetView(new Guid(source.ViewId)); SPViewFieldCollection viewfields = view.ViewFields; foreach (var viewfield in viewfields) { if (list.Fields.ContainsField(viewfield.ToString())) { try { string fieldname = viewfield.ToString().Replace("_x0020_", " "); SPField field = list.Fields.GetField(fieldname); FormField fld = new FormField(); if (inEditMode && Page.IsPostBack) //if (DesignMode)// && Page.IsPostBack) { fld.ControlMode = SPControlMode.Display; } else { fld.ControlMode = SPControlMode.New; } //fld.ControlMode = SPControlMode.New; fld.ListId = list.ID; fld.FieldName = field.InternalName; fld.ID = field.InternalName; fld.DisableInputFieldLabel = true; fld.InDesign = inEditMode; fld.IsValid = inEditMode; try { if (!string.IsNullOrEmpty(field.DefaultValue)) { if (field.FieldValueType == typeof(Boolean)) { bool isbool = false; fld.Value = (Boolean.TryParse(field.DefaultValue, out isbool)); fld.InputFieldLabel = string.Empty; } else { fld.Value = field.DefaultValue; } } } catch (Exception) { } canvas.Controls.Add(fld); if (field.Required) { InputFormRequiredFieldValidator required = new InputFormRequiredFieldValidator(); required.ID = "required_" + fld.ClientID; required.ControlToValidate = fld.ClientID; required.ValidationGroup = fld.ClientID; required.ErrorMessage = field.ValidationMessage; //required.EnableClientScript = true; required.BreakAfter = true; required.BreakBefore = false; required.Display = System.Web.UI.WebControls.ValidatorDisplay.Dynamic; canvas.Controls.Add(required); } if (field.Type == SPFieldType.Number) { SPFieldNumber Number = (SPFieldNumber)field; if (Number.MinimumValue != Double.MinValue && Number.MaximumValue != Double.MaxValue) { InputFormRangeValidator range = new InputFormRangeValidator(); range.ID = "range_" + fld.ClientID; range.ControlToValidate = fld.ClientID; range.ValidationGroup = fld.ClientID; range.ErrorMessage = field.ValidationMessage; //range.EnableClientScript = true; range.BreakAfter = true; range.BreakBefore = false; range.Display = System.Web.UI.WebControls.ValidatorDisplay.Dynamic; range.MaximumValue = Number.MaximumValue.ToString(); range.MinimumValue = Number.MinimumValue.ToString(); range.Type = System.Web.UI.WebControls.ValidationDataType.Double; canvas.Controls.Add(range); } } if (field.Type == SPFieldType.Currency) { SPFieldCurrency Currency = (SPFieldCurrency)field; if (Currency.MaximumValue != Double.MaxValue && Currency.MinimumValue != Double.MinValue) { InputFormRangeValidator range = new InputFormRangeValidator(); range.ID = "range_" + fld.ClientID; range.ControlToValidate = fld.ClientID; range.ValidationGroup = fld.ClientID; range.ErrorMessage = field.ValidationMessage; //range.EnableClientScript = true; range.BreakAfter = true; range.BreakBefore = false; range.Display = System.Web.UI.WebControls.ValidatorDisplay.Dynamic; range.MaximumValue = Currency.MaximumValue.ToString(); range.MinimumValue = Currency.MinimumValue.ToString(); range.Type = System.Web.UI.WebControls.ValidationDataType.Currency; canvas.Controls.Add(range); } } if (!string.IsNullOrEmpty(field.ValidationFormula)) { InputFormRegularExpressionValidator regex = new InputFormRegularExpressionValidator(); regex.ControlToValidate = fld.ClientID; regex.ValidationGroup = fld.ClientID; regex.ErrorMessage = fld.ErrorMessage; regex.ErrorMessage = field.ValidationMessage; //regex.EnableClientScript = true; regex.BreakAfter = true; regex.BreakBefore = false; regex.Display = System.Web.UI.WebControls.ValidatorDisplay.Dynamic; regex.ValidationExpression = field.ValidationFormula; canvas.Controls.Add(regex); } /* * if (field.Type == SPFieldType.MultiChoice) * { * InputFormCheckBoxListValidator checkboxes = new InputFormCheckBoxListValidator(); * //SPFieldMultiChoice choice = (SPFieldMultiChoice)field; * checkboxes.ControlToValidate = fld.ClientID; * checkboxes.ValidationGroup = fld.ClientID; * checkboxes.ErrorMessage = fld.ErrorMessage; * checkboxes.EnableClientScript = true; * //checkboxes.BreakAfter = true; * checkboxes.Display = System.Web.UI.WebControls.ValidatorDisplay.Dynamic; * canvas.Controls.Add(checkboxes); * * } */ } catch (Exception ex) { ex.Message.ToString(); } } } } }); }