Пример #1
0
        public void Hide_label_and_set_as_checkbox_control_if_checkbox_and_in_section()
        {
            _fieldConfiguration.Label("label");

            var config = Act(FieldDisplayType.Checkbox, FieldParent.Section);

            Assert.That(config.GetBagData <bool>("IsCheckboxControl"), Is.True);
            Assert.That(config.LabelText.ToHtmlString(), Is.EqualTo(string.Empty));
            Assert.That(config.HasLabel, Is.False);
        }
Пример #2
0
        /// <inheritdoc />
        public override void PrepareFieldConfiguration <TModel, T>(IFieldGenerator <TModel, T> fieldGenerator, IFieldGeneratorHandler <TModel, T> fieldGeneratorHandler, IFieldConfiguration fieldConfiguration, FieldParent fieldParent)
        {
            if (fieldParent == FieldParent.Form)
            {
                return;
            }

            fieldConfiguration.AddValidationClass("help-block");

            var displayType = fieldGeneratorHandler.GetDisplayType(fieldConfiguration.ToReadonly());

            if (NormalFieldTypes.Contains(displayType))
            {
                fieldConfiguration.Bag.CanBeInputGroup = true;
                fieldConfiguration.AddClass("form-control").AddLabelClass("control-label");
            }

            if (displayType == FieldDisplayType.Checkbox)
            {
                fieldConfiguration.Bag.IsCheckboxControl = true;
                // Hide the parent label otherwise it looks weird
                fieldConfiguration.Label("").WithoutLabel();
            }

            if (displayType == FieldDisplayType.List)
            {
                fieldConfiguration.Bag.IsRadioOrCheckboxList = true;
            }
        }
 /// <summary>
 /// Override the default label for the field.
 /// </summary>
 /// <param name="labelHtml">The text to use for the label</param>
 /// <param name="config">Field configuration to update</param>
 /// <returns>The instance of <see cref="IFieldConfiguration"/> to allow for method chaining</returns>
 public static IFieldConfiguration Label(this IFieldConfiguration config, Func <object, IHtmlString> labelHtml)
 {
     if (config != null)
     {
         return(config.Label(labelHtml(null)));
     }
     return(null);
 }