/// <summary>
        /// Creates the control main element.
        /// </summary>
        /// <returns></returns>
        protected override IFWHtmlElement CreateControl()
        {
            FWDivElement element = new FWDivElement();

            element.MergeAttributes(Attributes);
            if (!string.IsNullOrWhiteSpace(CustomCss))
            {
                element.AddCssClass(CustomCss);
            }

            element.Id       = Id;
            element.DataType = "fw-select";
            element.AddCssClass("m-form__group form-group");
            element.Attributes.Add("data-language", FWGlobalizationHelper.CurrentLocaleName);

            if (DisplayLabel)
            {
                FWLabelControl label = new FWLabelControl(Name, DisplayName, IsRequired, Tooltip);
                label.AddCssClass("control-label");
                element.Add(label.ToString());
            }

            FWSelectElement select = CreateSelect();

            element.Add(select);

            return(element);
        }
        private FWSelectElement CreateSelect()
        {
            var select = new FWSelectElement(Name);

            select.AddCssClass("m-select2 form-control");

            select.Attributes.Add("data-rule-required", IsRequired.ToString().ToLower());
            select.Attributes.Add("data-msg-required", string.Format(ViewResources.Validation_Required, DisplayName));
            select.Attributes.Add("data-minimumresultsforsearch", _minimumResultsForSearch.ToString());

            //Adds a width 100% to the select to make select2 pluging use all available space
            select.Attributes.Add("style", "width:100%");

            if (IsReadOnly)
            {
                select.Attributes.Add("readonly", "readonly");
            }

            if (_multiple)
            {
                select.Attributes.Add("multiple", "multiple");
            }

            if (!IsRequired)
            {
                string placeholder = GetModelResource("Placeholder", out bool resourceNotFound);
                select.Attributes.Add("data-placeholder", resourceNotFound ? ViewResources.Select_SelectOption : placeholder);
            }

            if (DataBind)
            {
                DataBind.Add("options", $"ds{_datasourceName}", true);
                DataBind.Add("optionsValue", "'id'");
                DataBind.Add("optionsText", "'value'");
                DataBind.AddMainBind(!_multiple ? FWBindConfiguration.VALUE : FWBindConfiguration.SELECTED_OPTIONS);
                select.DataBind = DataBind.CreateBind();
            }
            else if (_datasource != null)
            {
                foreach (var item in _datasource)
                {
                    var isSelected = _selected != null && item.Id == _selected.ToString();
                    select.Add(item, isSelected);
                }
            }

            select.Attributes.Add("data-allowclear", _allowClear.ToString().ToLower());
            return(select);
        }
Example #3
0
        private FWDivElement CreateGridDisplayResultsSelect()
        {
            var divSize = new FWDivElement();

            divSize.AddCssClass("btn-group bootstrap-select fw-pager-size");

            var select = new FWSelectElement("select_display");

            select.AddCssClass("form-control input-sm input-xsmall input-inline");
            select.Add("10", "10", _paginator.Display == 10);
            select.Add("20", "20", _paginator.Display == 20);
            select.Add("50", "50", _paginator.Display == 50);
            select.Add("30", "30", _paginator.Display == 30);
            select.Add("100", "100", _paginator.Display == 100);
            divSize.Add(select);

            return(divSize);
        }