/// <summary> /// Renders a submit button /// </summary> /// <param name="value">Button text</param> /// <param name="theme">Button theme</param> /// <param name="outerHtmlAttributes">HTML attributes of the form group</param> /// <param name="innerHtmlAttributes">HTML attributes of the inner div</param> /// <param name="buttonHtmlAttributes">HTML attributes of the button</param> public MvcHtmlString SubmitButton(string value, BsButtonTheme theme = BsButtonTheme.Default, object outerHtmlAttributes = null, object innerHtmlAttributes = null, object buttonHtmlAttributes = null) { // --- The form group that encapsulates the button var formGroup = new BsFormGroup { Depth = Depth + 1 }; formGroup.SetHtmlAttributes(outerHtmlAttributes); // --- The div with the buttons var div = new BsHtmlElement(HtmlTag.Div); div.SetHtmlAttributes(innerHtmlAttributes); div.ApplyColumnWidths(null, _form.InputWidthXs, _form.InputWidthSm, _form.InputWidthMd, _form.InputWidthLg); div.ApplyColumnOffsets(null, _form.LabelWidthXs, _form.LabelWidthSm, _form.LabelWidthMd, _form.LabelWidthLg); formGroup.AddChild(div); // --- The button in the div var button = new BsSubmitButton(value, theme); button.SetHtmlAttributes(buttonHtmlAttributes); button.Attr(NgTag.NgDisabled, string.Format("{0}.$invalid", _form.FormName)); div.AddChild(button); return(formGroup.Markup); }
/// <summary> /// Builds a horizontal static text control /// </summary> /// <param name="modelMetadata">Model metadata</param> public MvcHtmlString BuildHorizontalStatic(ModelMetadata modelMetadata) { // --- The form group that encapsulates the label and the control var propName = CamelCase(modelMetadata.PropertyName); var formGroup = new BsFormGroup { Depth = _formBuilder.Depth + 1 }; var label = CreateTextLabel(modelMetadata); var staticDiv = new BsHtmlElement(HtmlTag.Div); staticDiv.ApplyColumnWidths(null, _formBuilder.BsForm.InputWidthXs, _formBuilder.BsForm.InputWidthSm, _formBuilder.BsForm.InputWidthMd, _formBuilder.BsForm.InputWidthLg); var staticText = new BsHtmlElement(HtmlTag.P); staticText.CssClass(BsClass.Control.Static); staticText.AddChild(new HtmlText(modelMetadata.Model.ToString())); staticDiv.AddChild(staticText); var hidden = new BsHtmlElement(HtmlTag.Input) .Attr(HtmlAttr.Type, "hidden") .Attr(HtmlAttr.Id, propName) .Attr(HtmlAttr.Name, propName) .Attr(NgTag.NgModel, string.Format("model.{0}", propName)); if (modelMetadata.Model != null) { var modelValue = modelMetadata.Model.ToString(); hidden .Attr(HtmlAttr.Value, modelValue) .Attr(NgTag.NgInit, string.Format("model.{0}={1}", propName, JsonConvert.SerializeObject(modelMetadata.Model))); } formGroup.AddChild(label).AddChild(staticDiv).AddChild(hidden); return(formGroup.Markup); }
/// <summary> /// Builds a horizontal input control /// </summary> /// <param name="modelMetadata">Model metadata</param> /// <param name="inputTagType">Type of the input tag</param> /// <param name="autoFocus">Autofocus type</param> /// <param name="validationOption">Validation type</param> public MvcHtmlString BuildHorizontalInput(ModelMetadata modelMetadata, InputTagType inputTagType, AutoFocus autoFocus, ValidationOption validationOption) { // --- The form group that encapsulates the label and the control var propName = CamelCase(modelMetadata.PropertyName); var formGroup = new BsFormGroup { Depth = _formBuilder.Depth + 1 }; var condition = string.Format("{0}{1}", "{0}.{1}.$invalid", validationOption == ValidationOption.WhenDirty ? " && {0}.{1}.$dirty" : ""); formGroup.Attr(NgTag.NgClass, string.Format("{{'has-error': " + condition + ", 'has-feedback': " + condition + "}}", _formBuilder.BsForm.FormName, propName)); if (inputTagType == InputTagType.Text) { var label = CreateTextLabel(modelMetadata); var inputDiv = new BsHtmlElement(HtmlTag.Div); inputDiv.ApplyColumnWidths(null, _formBuilder.BsForm.InputWidthXs, _formBuilder.BsForm.InputWidthSm, _formBuilder.BsForm.InputWidthMd, _formBuilder.BsForm.InputWidthLg); var input = CreateInput(inputTagType, autoFocus, modelMetadata, propName); // --- Assemble the elements formGroup.AddChild(label).AddChild(inputDiv); inputDiv.AddChild(input); // --- Add optional help text if (!string.IsNullOrEmpty(modelMetadata.Description)) { var helpText = new BsHtmlElement(HtmlTag.Span); helpText.CssClass(BsClass.Control.Help); helpText.AddChild(new HtmlText(modelMetadata.Description)); inputDiv.AddChild(helpText); } // --- Create validation tags AddValidationTags(inputDiv, modelMetadata, validationOption); } else if (inputTagType == InputTagType.CheckBox) { var sizingDiv = new BsHtmlElement(HtmlTag.Div); sizingDiv.ApplyColumnWidths(null, _formBuilder.BsForm.InputWidthXs, _formBuilder.BsForm.InputWidthSm, _formBuilder.BsForm.InputWidthMd, _formBuilder.BsForm.InputWidthLg); sizingDiv.ApplyColumnOffsets(null, _formBuilder.BsForm.LabelWidthXs, _formBuilder.BsForm.LabelWidthSm, _formBuilder.BsForm.LabelWidthMd, _formBuilder.BsForm.LabelWidthLg); var checkBoxDiv = new BsHtmlElement(HtmlTag.Div).CssClass(BsClass.Control.CheckBox); var label = new BsHtmlElement(HtmlTag.Label); var input = CreateInput(inputTagType, autoFocus, modelMetadata, propName); input.Attr(modelMetadata.Model != null && modelMetadata.Model.ToString().ToLower() == "true", HtmlAttr.Checked, HtmlAttr.Checked); var hiddenInput = new BsHtmlElement(HtmlTag.Input) .Attr(HtmlAttr.Name, modelMetadata.PropertyName) .Attr(HtmlAttr.Type, HtmlInputType.Hidden) .Attr(HtmlAttr.Value, "false"); // --- Assemble the elements formGroup.AddChild(sizingDiv); sizingDiv.AddChild(checkBoxDiv); checkBoxDiv.AddChild(label); label .AddChild(input) .AddChild(new HtmlText(modelMetadata.DisplayName ?? modelMetadata.PropertyName)) .AddChild(hiddenInput); } return(formGroup.Markup); }