示例#1
0
        public TagBuilder_Password(DynamicComponentBaseFor <TModel, TProperty> dynamicComponentBase)
            : base("input", dynamicComponentBase)
        {
            /* Adicionar os atributos de acordo com o que for obtido no Metadata... */
            //TagElement.AddInputTypeAttribute(fieldType);
            TagElement.AddInputAttributeStaticValue("type", "password");
            int?minimumLength = (int?)this.ComponentBase.MetadataAttributes.GetValue <DataType>("Minimum", "Length") ?? (int?)this.ComponentBase.MetadataAttributes.GetValue <DataType>("StringLength", "MinimumLength");

            TagElement.AddInputAttributeIsNotNullAndExpressionIsTrue("minlength", minimumLength, minimumLength.HasValue && minimumLength.Value > 0);
            int?maximumLength = (int?)this.ComponentBase.MetadataAttributes.GetValue <DataType>("Maximum", "Length") ?? (int?)this.ComponentBase.MetadataAttributes.GetValue <DataType>("StringLength", "MaximumLength");

            TagElement.AddInputAttributeIsNotNullAndExpressionIsTrue("maxlength", maximumLength, maximumLength.HasValue && maximumLength.Value > 0);
            TagElement.MergeInputAttributeIsNotNull("class", this.ComponentBase.MetadataAttributes.GetValue <object>("OnlyNumber", "ClassDecorator"));
            TagElement.MergeInputAttributeIsNotNull("class", this.ComponentBase.MetadataAttributes.GetValue <object>("Currency", "ClassDecorator"));
            TagElement.MergeInputAttributeIsNotNull("pattern", this.ComponentBase.MetadataAttributes.GetValue <object>("Currency", "Pattern"));
            TagElement.MergeInputAttributeIsNotNull("class", this.ComponentBase.MetadataAttributes.GetValue <object>("NoEspecialChars", "ClassDecorator"));

            /* Adicionar os atributos de acordo com o que for obtido no HtmlAttributes... */
            TagElement.MergeInputAttributeHtmlAttributes("class", this.ComponentBase.HtmlAttributes);
            TagElement.MergeInputAttributeHtmlAttributes("style", this.ComponentBase.HtmlAttributes);
            TagElement.AddInputAttributeHtmlAttributes("minlength", this.ComponentBase.HtmlAttributes);
            TagElement.AddInputAttributeHtmlAttributes("maxlength", this.ComponentBase.HtmlAttributes);

            /* Injetando o Valor no Input... */
            this.Value = this.ComponentBase.FieldValue;
            TagElement.AddInputAttributeIsNotNull("value", this.Value);
        }
        private void InicializeTagElement()
        {
            this.TagElement = new TagBuilder(TagElementType);
            //TagElement.GenerateId(fieldFullName);
            TagElement.AddInputAttributeIsNotNull("id", this.ComponentBase.SanitizedId);
            TagElement.AddInputAttributeIsNotNull("name", this.ComponentBase.FieldFullName);

            //...............................................................................................................................................................\\
            bool _IsRequired = !this.ComponentBase.FieldIsNullable || this.ComponentBase.MetadataAttributes.GetValue <bool>("Common", "IsRequired");

            if (_IsRequired)
            {
                TagElement.AddInputAttributeStaticValue("required", null);
            }
            bool _IsNullable = this.ComponentBase.FieldIsNullable || this.ComponentBase.MetadataAttributes.GetValue <bool>("Common", "IsNullable") || this.ComponentBase.MetadataAttributes.GetValue <bool>("Common", "IsNullableValueType");

            //...............................................................................................................................................................\\


            /* Adicionar os atributos de acordo com o que for obtido no MetaData... */
            //TagElement.AddInputTypeAttribute(fieldType);
            TagElement.AddInputAttributeStaticValue("class", "form-control");
            TagElement.AddInputAttributeIsNotNull("autofocus", this.ComponentBase.MetadataAttributes.GetValue <object>("Common", "Autofocus"));
            TagElement.AddInputAttributeIsNotNullAndExpressionIsTrue("required", null, (bool)this.ComponentBase.MetadataAttributes.GetValue <object>("Common", "IsRequired"));
            TagElement.AddInputAttributeIsNotNullAndExpressionIsTrue("readonly", null, this.ComponentBase.FieldIsReadOnly || (bool)this.ComponentBase.MetadataAttributes.GetValue <object>("Common", "IsReadOnly"));
            TagElement.AddInputAttributeIsNotNull("title", this.ComponentBase.MetadataAttributes.GetValue <object>("Common", "Description"));
            TagElement.AddInputAttributeIsNotNull("placeholder", this.ComponentBase.MetadataAttributes.GetValue <object>("PlaceHolder", "Text") ?? this.ComponentBase.MetadataAttributes.GetValue <object>("Common", "Watermark"));

            //...............................................................................................................................................................\\

            TagElement.AddInputAttributeIsNotNullAndExpressionIsTrue("required", null, !this.ComponentBase.FieldIsNullable);
            TagElement.AddInputAttributeIsNotNullAndExpressionIsTrue("readonly", null, this.ComponentBase.FieldIsReadOnly);
            TagElement.AddInputAttributeIsNotNullAndExpressionIsTrue("disabled", null, this.ComponentBase.FieldIsDisabled);

            //...............................................................................................................................................................\\

            /* Adicionar os atributos de acordo com o que for obtido no HtmlAttributes... */
            TagElement.AddInputAttributeHtmlAttributes("autofocus", this.ComponentBase.HtmlAttributes);
            TagElement.AddInputAttributeHtmlAttributes("required", this.ComponentBase.HtmlAttributes);
            TagElement.AddInputAttributeHtmlAttributes("readonly", this.ComponentBase.HtmlAttributes);
            TagElement.AddInputAttributeHtmlAttributes("disabled", this.ComponentBase.HtmlAttributes);
            TagElement.AddInputAttributeHtmlAttributes("title", this.ComponentBase.HtmlAttributes);
            TagElement.AddInputAttributeHtmlAttributes("placeholder", this.ComponentBase.HtmlAttributes);

            //...............................................................................................................................................................\\

            /* Adicionar os atributos de acordo com o que for obtido no Data-Val... */
            //TagElement.AddInputAttributeStaticValue("data-val", "true");
            TagElement.AddInputAttributeIsNotNull("data-val-required", this.ComponentBase.MetadataAttributes.GetValue <object>("Required", "ErrorMessage"));
            //TagElement.AddInputAttributeStaticValue("data-val-regex-pattern", "");
            //TagElement.AddInputAttributeStaticValue("data-val-regex", "");

            this.Value = this.ComponentBase.FieldValue;
        }
示例#3
0
        public TagBuilder_Checkbox(DynamicComponentBaseFor <TModel, TProperty> dynamicComponentBase)
            : base(CustomAttributesHelpers.GetInputElementTypeByDataType((DataType)dynamicComponentBase.MetadataAttributes.GetValue <DataType>("DataType", "DataType")), dynamicComponentBase)
        {
            /* Adicionar os atributos de acordo com o que for obtido no Metadata... */
            TagElement.AddInputAttributeStaticValue("type", "checkbox");

            /* Adicionar os atributos de acordo com o que for obtido no HtmlAttributes... */
            TagElement.MergeInputAttributeHtmlAttributes("class", this.ComponentBase.HtmlAttributes);
            TagElement.MergeInputAttributeHtmlAttributes("style", this.ComponentBase.HtmlAttributes);

            /* Injetando o Valor no Input... */
            this.Value = this.ComponentBase.FieldValue;
            TagElement.AddInputAttributeIsNotNull("value", this.Value);
        }
        public TagBuilder_Label(DynamicComponentBaseFor <TModel, TProperty> dynamicComponentBase, string id, string caption, string forInput, string tooltip = null)
            : base("label", dynamicComponentBase)
        {
            /* Adicionar os atributos de acordo com os parâmetros informados... */
            TagElement.AddInputAttributeIsNotNullAndExpressionIsTrue("id", id ?? $"label.{forInput}", (id ?? $"label.{forInput}") != null);
            TagElement.AddInputAttributeIsNotNullAndExpressionIsTrue("for", forInput, forInput != null);
            if (tooltip != null && !string.IsNullOrEmpty(tooltip))
            {
                TagElement.AddInputAttributeStaticValue("data-toggle", "tooltip");
                TagElement.AddInputAttributeStaticValue("data-placement", "top");
                TagElement.AddInputAttributeIsNotNullAndExpressionIsTrue("data-original-title", tooltip, tooltip != null);
            }

            /* Adicionar os atributos de acordo com o que for obtido no HtmlAttributes... */
            TagElement.AddInputAttributeHtmlAttributes("class", this.ComponentBase.HtmlAttributes);
            TagElement.AddInputAttributeHtmlAttributes("style", this.ComponentBase.HtmlAttributes);

            /* Injetando o Valor no Input... */
            TagElement.InnerHtml = caption;
        }