Exemple #1
0
        /// <inheritdoc />
        public IHtmlString GetFieldHtml(IReadonlyFieldConfiguration fieldConfiguration)
        {
            fieldConfiguration = fieldConfiguration ?? new FieldConfiguration();
            if (fieldConfiguration.FieldHtml != null)
            {
                return(fieldConfiguration.FieldHtml);
            }

            return(FieldGeneratorHandlersRouter <TModel, T> .GetHandler(this).GenerateFieldHtml(fieldConfiguration));
        }
        /// <inheritdoc />
        public IReadonlyFieldConfiguration PrepareFieldConfiguration(IFieldConfiguration fieldConfiguration, FieldParent fieldParent)
        {
            fieldConfiguration = fieldConfiguration ?? new FieldConfiguration();
            if (!string.IsNullOrEmpty(Metadata.EditFormatString) && string.IsNullOrEmpty(fieldConfiguration.FormatString))
            {
                fieldConfiguration.WithFormatString(Metadata.EditFormatString);
            }
            if (!string.IsNullOrEmpty(Metadata.NullDisplayText) && string.IsNullOrEmpty(fieldConfiguration.NoneString))
            {
                fieldConfiguration.WithNoneAs(Metadata.NullDisplayText);
            }
            if (Metadata.IsReadOnly)
            {
                fieldConfiguration.Readonly();
            }
            if (fieldConfiguration.Hint != null)
            {
                var hintId = $"{HtmlHelper.GetFullHtmlFieldName(FieldProperty)}--Hint";
                fieldConfiguration.Attr("aria-describedby", hintId).WithHintId(hintId);
            }

            var handler = FieldGeneratorHandlersRouter <TModel, T> .GetHandler(this);

            handler.PrepareFieldConfiguration(fieldConfiguration);
            Template.PrepareFieldConfiguration(this, handler, fieldConfiguration, fieldParent);

            // Do this after the handler above since it may change FieldDisplayType
            var disabledOrReadonly           = fieldConfiguration.Attributes.Has("readonly") || fieldConfiguration.Attributes.Has("disabled");
            var isCheckboxList               = fieldConfiguration.DisplayType == FieldDisplayType.List && this.HasMultipleValues();
            var userAlreadySpecifiedRequired = fieldConfiguration.Attributes.Has("required");

            if (Metadata.IsRequired && !disabledOrReadonly && !userAlreadySpecifiedRequired && !isCheckboxList)
            {
                fieldConfiguration.Required();
            }

            return(fieldConfiguration);
        }
Exemple #3
0
        /// <inheritdoc />
        public IReadonlyFieldConfiguration PrepareFieldConfiguration(IFieldConfiguration fieldConfiguration, FieldParent fieldParent)
        {
            fieldConfiguration = fieldConfiguration ?? new FieldConfiguration();
            if (!string.IsNullOrEmpty(Metadata.EditFormatString) && string.IsNullOrEmpty(fieldConfiguration.FormatString))
            {
                fieldConfiguration.WithFormatString(Metadata.EditFormatString);
            }
            if (!string.IsNullOrEmpty(Metadata.NullDisplayText) && string.IsNullOrEmpty(fieldConfiguration.NoneString))
            {
                fieldConfiguration.WithNoneAs(Metadata.NullDisplayText);
            }
            if (Metadata.IsReadOnly)
            {
                fieldConfiguration.Readonly();
            }

            var handler = FieldGeneratorHandlersRouter <TModel, T> .GetHandler(this);

            handler.PrepareFieldConfiguration(fieldConfiguration);
            Template.PrepareFieldConfiguration(this, handler, fieldConfiguration, fieldParent);

            return(fieldConfiguration);
        }