public virtual void Visit(FormTextBox formTextBox, HtmlContainer htmlContainer)
        {
            HtmlFieldset htmlFieldset = verbose ? new HtmlFieldset(formTextBox.Path) : new HtmlFieldset();

            htmlFieldset.Class.Add("formTextBox");

            if (!string.IsNullOrWhiteSpace(formTextBox.CssClass))
            {
                htmlFieldset.Class.AddRange(formTextBox.CssClass.Split(' ').Where(s => s != string.Empty));
            }

            htmlFieldset.Class.Add("form-group");

            if (!string.IsNullOrWhiteSpace(formTextBox.Path))
            {
                htmlFieldset.Class.Add(string.Format("{0}{1}", "formId", formTextBox.Path));
            }

            htmlFieldset.Class.Add("formField");

            if (initialize)
            {
                htmlFieldset.Class.Add(formTextBox.IsRequired ? "formRequired" : "formOptional");
            }
            else
            {
                if (formTextBox.HasValue)
                {
                    htmlFieldset.Class.Add(formTextBox.IsValid ? "formValid" : "formInvalid");
                }
                else
                {
                    htmlFieldset.Class.Add(formTextBox.IsRequired ? "formNotEntered" : "formOptional");
                }
            }

            htmlFieldset.Hidden.Value = formTextBox.IsHidden;

            htmlContainer.Add(htmlFieldset);

            HtmlTextBox htmlTextBox = new HtmlTextBox(formTextBox.Path);

            htmlTextBox.Class.Add("form-control");
            htmlTextBox.Disabled.Value = formTextBox.IsDisabled;
            htmlTextBox.ReadOnly.Value = formTextBox.IsReadOnly;
            htmlTextBox.Value.Value    = formTextBox.Value;

            string placeholder = null;

            if (!string.IsNullOrWhiteSpace(formTextBox.Placeholder))
            {
                if (formTextBox.IsRequired && formTextBox.IsRequiredInPlaceholder && !string.IsNullOrWhiteSpace(formTextBox.RequiredMark))
                {
                    placeholder = string.Format("{0} {1}", formTextBox.Placeholder, formTextBox.RequiredMark);
                }
                else if (!formTextBox.IsRequired && formTextBox.IsOptionalInPlaceholder && !string.IsNullOrWhiteSpace(formTextBox.OptionalMark))
                {
                    placeholder = string.Format("{0} {1}", formTextBox.Placeholder, formTextBox.OptionalMark);
                }
                else
                {
                    placeholder = formTextBox.Placeholder;
                }
            }

            htmlTextBox.Placeholder.Value = placeholder;

            if (!initialize && firstInvalidId == null)
            {
                if (formTextBox.IsRequired && !formTextBox.HasValue || !formTextBox.IsValid)
                {
                    firstInvalidId = htmlTextBox.Id.Value;
                }
            }

            switch (formTextBox.OrderElements)
            {
            case OrderElements.LabelMarkInput:

                AddLabelMark(formTextBox, htmlTextBox, htmlFieldset);
                htmlFieldset.Add(htmlTextBox);

                break;

            case OrderElements.MarkLabelInput:

                AddMarkLabel(formTextBox, htmlTextBox, htmlFieldset);
                htmlFieldset.Add(htmlTextBox);

                break;

            case OrderElements.InputLabelMark:

                htmlFieldset.Add(htmlTextBox);
                AddLabelMark(formTextBox, htmlTextBox, htmlFieldset);

                break;

            case OrderElements.InputMarkLabel:

                htmlFieldset.Add(htmlTextBox);
                AddMarkLabel(formTextBox, htmlTextBox, htmlFieldset);

                break;

            case OrderElements.LabelInputMark:

                AddLabel(formTextBox, htmlTextBox, htmlFieldset);
                htmlFieldset.Add(htmlTextBox);
                AddMark(formTextBox, htmlTextBox, htmlFieldset);

                break;

            case OrderElements.MarkInputLabel:

                AddMark(formTextBox, htmlTextBox, htmlFieldset);
                htmlFieldset.Add(htmlTextBox);
                AddLabel(formTextBox, htmlTextBox, htmlFieldset);

                break;

            default:
            case OrderElements.NotSet:

                break;
            }

            if (initialize)
            {
                return;
            }

            string message = null;

            if (formTextBox.UseLastMessage)
            {
                if (!string.IsNullOrEmpty(formTextBox.LastMessage))
                {
                    message = formTextBox.LastMessage;
                }
            }
            else if (formTextBox.IsRequired && !formTextBox.HasValue)
            {
                message = formTextBox.RequiredMessage;
            }
            else if (!formTextBox.IsValid)
            {
                message = formTextBox.ValidationMessage;
            }

            if (message == null)
            {
                return;
            }

            HtmlLabel htmlLabelMessage = new HtmlLabel(verbose ? string.Format("{0}{1}", formTextBox.Path, "Message") : "");

            htmlLabelMessage.Class.Add("formValidationMessage");
            htmlLabelMessage.For.Value = htmlTextBox.Id.Value;
            htmlLabelMessage.Add(new HtmlText(message));
            htmlFieldset.Add(htmlLabelMessage);
        }
Beispiel #2
0
        public virtual void Visit(FormDatePicker formDatePicker, HtmlContainer htmlContainer)
        {
            HtmlFieldset htmlFieldset = verbose ? new HtmlFieldset(formDatePicker.Path) : new HtmlFieldset();

            htmlFieldset.Class.Add("formDatePicker");

            if (!string.IsNullOrWhiteSpace(formDatePicker.CssClass))
            {
                htmlFieldset.Class.AddRange(formDatePicker.CssClass.Split(' ').Where(s => s != string.Empty));
            }

            htmlFieldset.Class.Add("form-group");

            if (!string.IsNullOrWhiteSpace(formDatePicker.Path))
            {
                htmlFieldset.Class.Add(string.Format("{0}{1}", "formId", formDatePicker.Path));
            }

            htmlFieldset.Class.Add("formField");

            if (initialize)
            {
                htmlFieldset.Class.Add(formDatePicker.IsRequired ? "formRequired" : "formOptional");
            }
            else
            {
                if (!formDatePicker.IsRequired || formDatePicker.HasValue)
                {
                    htmlFieldset.Class.Add(formDatePicker.IsValid ? "formValid" : "formInvalid");
                }
                else
                {
                    htmlFieldset.Class.Add(formDatePicker.IsRequired ? "formNotEntered" : "formOptional");
                }
            }

            htmlFieldset.Hidden.Value = formDatePicker.IsHidden;

            htmlContainer.Add(htmlFieldset);

            HtmlDatePicker htmlDatePicker = new HtmlDatePicker(formDatePicker.Path);

            htmlDatePicker.Class.Add("form-control");
            htmlDatePicker.Disabled.Value       = formDatePicker.IsDisabled;
            htmlDatePicker.ReadOnly.Value       = formDatePicker.IsReadOnly;
            htmlDatePicker.DataDateFormat.Value = formDatePicker.DateFormat;
            htmlDatePicker.Value.Value          = formDatePicker.HasValue ? formDatePicker.Value.ToString(formDatePicker.DateFormat.Replace('m', 'M'), CultureInfo.InvariantCulture) : "";
            htmlDatePicker.Placeholder.Value    = !string.IsNullOrEmpty(formDatePicker.Placeholder) ? formDatePicker.Placeholder : null;
            htmlDatePicker.AutoComplete.Value   = "off";
            if (formDatePicker.IsReadOnly)
            {
                htmlDatePicker.DataProvide.Value = null;
            }

            if (!initialize && firstInvalidId == null)
            {
                if (formDatePicker.IsRequired && !formDatePicker.HasValue || !formDatePicker.IsValid)
                {
                    firstInvalidId = htmlDatePicker.Id.Value;
                }
            }

            switch (formDatePicker.OrderElements)
            {
            case OrderElements.LabelMarkInput:

                AddLabelMark(formDatePicker, htmlDatePicker, htmlFieldset);
                htmlFieldset.Add(htmlDatePicker);

                break;

            case OrderElements.MarkLabelInput:

                AddMarkLabel(formDatePicker, htmlDatePicker, htmlFieldset);
                htmlFieldset.Add(htmlDatePicker);

                break;

            case OrderElements.InputLabelMark:

                htmlFieldset.Add(htmlDatePicker);
                AddLabelMark(formDatePicker, htmlDatePicker, htmlFieldset);

                break;

            case OrderElements.InputMarkLabel:

                htmlFieldset.Add(htmlDatePicker);
                AddMarkLabel(formDatePicker, htmlDatePicker, htmlFieldset);

                break;

            case OrderElements.LabelInputMark:

                AddLabel(formDatePicker, htmlDatePicker, htmlFieldset);
                htmlFieldset.Add(htmlDatePicker);
                AddMark(formDatePicker, htmlDatePicker, htmlFieldset);

                break;

            case OrderElements.MarkInputLabel:

                AddMark(formDatePicker, htmlDatePicker, htmlFieldset);
                htmlFieldset.Add(htmlDatePicker);
                AddLabel(formDatePicker, htmlDatePicker, htmlFieldset);

                break;

            default:
            case OrderElements.NotSet:

                break;
            }

            if (initialize)
            {
                return;
            }

            string message = null;

            if (formDatePicker.UseLastMessage)
            {
                if (!string.IsNullOrEmpty(formDatePicker.LastMessage))
                {
                    message = formDatePicker.LastMessage;
                }
            }
            else if (formDatePicker.IsRequired && !formDatePicker.HasValue)
            {
                message = formDatePicker.RequiredMessage;
            }
            else if (!formDatePicker.IsValid)
            {
                message = formDatePicker.ValidationMessage;
            }

            if (message == null)
            {
                return;
            }

            HtmlLabel htmlLabelMessage = new HtmlLabel(verbose ? string.Format("{0}{1}", formDatePicker.Path, "Message") : "");

            htmlLabelMessage.Class.Add("formValidationMessage");
            htmlLabelMessage.For.Value = htmlDatePicker.Id.Value;
            htmlLabelMessage.Add(new HtmlText(message));
            htmlFieldset.Add(htmlLabelMessage);
        }
Beispiel #3
0
        public virtual void Visit(FormSelect formSelect, HtmlContainer htmlContainer)
        {
            HtmlFieldset htmlFieldset = verbose ? new HtmlFieldset(formSelect.Path) : new HtmlFieldset();

            htmlFieldset.Class.Add("formSelect");

            if (!string.IsNullOrWhiteSpace(formSelect.CssClass))
            {
                htmlFieldset.Class.AddRange(formSelect.CssClass.Split(' ').Where(s => s != string.Empty));
            }

            htmlFieldset.Class.Add("form-group");

            if (!string.IsNullOrWhiteSpace(formSelect.Path))
            {
                htmlFieldset.Class.Add(string.Format("{0}{1}", "formId", formSelect.Path));
            }

            htmlFieldset.Class.Add("formField");

            if (initialize)
            {
                htmlFieldset.Class.Add(formSelect.IsRequired ? "formRequired" : "formOptional");
            }
            else
            {
                if (!formSelect.IsRequired || formSelect.HasValue)
                {
                    htmlFieldset.Class.Add("formValid");
                }
                else
                {
                    htmlFieldset.Class.Add(formSelect.IsRequired ? "formNotEntered" : "formOptional");
                }
            }

            htmlFieldset.Hidden.Value = formSelect.IsHidden;

            htmlContainer.Add(htmlFieldset);

            HtmlSelect htmlSelect = formSelect.Size.HasValue ?
                                    new HtmlSelect(formSelect.Path, formSelect.Size.Value, formSelect.Update) :
                                    new HtmlSelect(formSelect.Path, formSelect.IsMultiSelect, formSelect.Update);

            htmlSelect.Class.Add("form-control");
            htmlSelect.Disabled.Value = formSelect.IsDisabled;

            if (!initialize && firstInvalidId == null)
            {
                if (formSelect.IsRequired && !formSelect.HasValue || !formSelect.IsValid)
                {
                    firstInvalidId = htmlSelect.Id.Value;
                }
            }

            switch (formSelect.OrderElements)
            {
            case OrderElements.LabelMarkInput:

                AddLabelMark(formSelect, htmlSelect, htmlFieldset);
                htmlFieldset.Add(htmlSelect);

                break;

            case OrderElements.MarkLabelInput:

                AddMarkLabel(formSelect, htmlSelect, htmlFieldset);
                htmlFieldset.Add(htmlSelect);

                break;

            case OrderElements.InputLabelMark:

                htmlFieldset.Add(htmlSelect);
                AddLabelMark(formSelect, htmlSelect, htmlFieldset);

                break;

            case OrderElements.InputMarkLabel:

                htmlFieldset.Add(htmlSelect);
                AddMarkLabel(formSelect, htmlSelect, htmlFieldset);

                break;

            case OrderElements.LabelInputMark:

                AddLabel(formSelect, htmlSelect, htmlFieldset);
                htmlFieldset.Add(htmlSelect);
                AddMark(formSelect, htmlSelect, htmlFieldset);

                break;

            case OrderElements.MarkInputLabel:

                AddMark(formSelect, htmlSelect, htmlFieldset);
                htmlFieldset.Add(htmlSelect);
                AddLabel(formSelect, htmlSelect, htmlFieldset);

                break;

            default:
            case OrderElements.NotSet:

                break;
            }

            foreach (var formOption in formSelect.Content)
            {
                Visit(formOption, htmlSelect);
            }

            if (initialize)
            {
                return;
            }

            string message = null;

            if (formSelect.UseLastMessage)
            {
                if (!string.IsNullOrEmpty(formSelect.LastMessage))
                {
                    message = formSelect.LastMessage;
                }
            }
            else if (formSelect.IsRequired && !formSelect.HasValue)
            {
                message = formSelect.RequiredMessage;
            }
            else if (!formSelect.IsValid)
            {
                message = formSelect.ValidationMessage;
            }

            if (message == null)
            {
                return;
            }

            HtmlLabel htmlLabelMessage = new HtmlLabel(verbose ? string.Format("{0}{1}", formSelect.Path, "Message") : "");

            htmlLabelMessage.Class.Add("formValidationMessage");
            htmlLabelMessage.For.Value = htmlSelect.Id.Value;
            htmlLabelMessage.Add(new HtmlText(message));
            htmlFieldset.Add(htmlLabelMessage);
        }
Beispiel #4
0
        public virtual void Visit(FormCheckBox formCheckBox, HtmlContainer htmlContainer)
        {
            HtmlFieldset htmlFieldset = verbose ? new HtmlFieldset(formCheckBox.Path) : new HtmlFieldset();

            htmlFieldset.Class.Add("formCheckBox");

            if (!string.IsNullOrWhiteSpace(formCheckBox.CssClass))
            {
                htmlFieldset.Class.AddRange(formCheckBox.CssClass.Split(' ').Where(s => s != string.Empty));
            }

            htmlFieldset.Class.AddRange(new string[] { "form-group", "switchBlock", "d-flex", "justify-content-between" });

            if (!string.IsNullOrWhiteSpace(formCheckBox.Path))
            {
                htmlFieldset.Class.Add(string.Format("{0}{1}", "formId", formCheckBox.Path));
            }

            htmlFieldset.Class.Add("formField");

            if (initialize)
            {
                htmlFieldset.Class.Add(formCheckBox.IsRequired ? "formRequired" : "formOptional");
            }
            else
            {
                if (!formCheckBox.IsRequired || formCheckBox.Value)
                {
                    htmlFieldset.Class.Add("formValid");
                }
                else
                {
                    htmlFieldset.Class.Add(formCheckBox.IsRequired ? "formNotEntered" : "formOptional");
                }
            }

            htmlFieldset.Hidden.Value = formCheckBox.IsHidden;

            htmlContainer.Add(htmlFieldset);

            HtmlLabel htmlLabel = CreateCheckBox(formCheckBox);

            HtmlCheckBox htmlCheckBox = htmlLabel.Contents.Single(c => c is HtmlCheckBox) as HtmlCheckBox;

            if (!initialize && firstInvalidId == null)
            {
                if (formCheckBox.IsRequired && !formCheckBox.HasValue || !formCheckBox.IsValid)
                {
                    firstInvalidId = htmlCheckBox.Id.Value;
                }
            }

            switch (formCheckBox.OrderElements)
            {
            case OrderElements.LabelMarkInput:

                AddLabelMark(formCheckBox, htmlCheckBox, htmlFieldset);
                htmlFieldset.Add(htmlLabel);

                break;

            case OrderElements.MarkLabelInput:

                AddMarkLabel(formCheckBox, htmlCheckBox, htmlFieldset);
                htmlFieldset.Add(htmlLabel);

                break;

            case OrderElements.InputLabelMark:

                htmlFieldset.Add(htmlLabel);
                AddLabelMark(formCheckBox, htmlCheckBox, htmlFieldset);

                break;

            case OrderElements.InputMarkLabel:

                htmlFieldset.Add(htmlLabel);
                AddMarkLabel(formCheckBox, htmlCheckBox, htmlFieldset);

                break;

            case OrderElements.LabelInputMark:

                AddLabel(formCheckBox, htmlCheckBox, htmlFieldset);
                htmlFieldset.Add(htmlLabel);
                AddMark(formCheckBox, htmlCheckBox, htmlFieldset);

                break;

            case OrderElements.MarkInputLabel:

                AddMark(formCheckBox, htmlCheckBox, htmlFieldset);
                htmlFieldset.Add(htmlLabel);
                AddLabel(formCheckBox, htmlCheckBox, htmlFieldset);

                break;

            default:
            case OrderElements.NotSet:

                break;
            }

            if (initialize)
            {
                return;
            }

            string message = null;

            if (formCheckBox.UseLastMessage)
            {
                if (!string.IsNullOrEmpty(formCheckBox.LastMessage))
                {
                    message = formCheckBox.LastMessage;
                }
            }
            else if (formCheckBox.IsRequired && !formCheckBox.Value)
            {
                message = formCheckBox.RequiredMessage;
            }
            else if (!formCheckBox.IsValid)
            {
                message = formCheckBox.ValidationMessage;
            }

            if (message == null)
            {
                return;
            }

            HtmlLabel htmlLabelMessage = new HtmlLabel(verbose ? string.Format("{0}{1}", formCheckBox.Path, "Message") : "");

            htmlLabelMessage.Class.Add("formValidationMessage");
            htmlLabelMessage.For.Value = htmlCheckBox.Id.Value;
            htmlLabelMessage.Add(new HtmlText(formCheckBox.RequiredMessage));
            htmlFieldset.Add(htmlLabelMessage);
        }