Exemple #1
0
        /// <summary> Creates a new instance with the default configuration. </summary>
        public static Textarea Init(int?id = null, string label = null, string description = null, bool?required = null, bool?inlineMode = null, int?col = null)
        {
            Textarea obj = new Textarea();

            obj.Id       = id ?? 0;
            obj.Type     = FormElementType.Textarea;
            obj.Status   = (int)Base.Enums.Status.Active;
            obj.Visible  = true;
            obj.Disabled = false;
            obj.Index    = 0;

            obj.Label       = label;
            obj.Description = description;

            obj.MaxLength   = null;
            obj.CharCounter = false;
            obj.Required    = required ?? false;
            obj.FieldSize   = null;
            obj.FieldHeight = null;
            obj.InlineMode  = inlineMode ?? false;

            //obj.PersonalizationOptions = null;

            obj.Column = col ?? 1;


            return(obj);
        }
Exemple #2
0
        /// <summary> Add Textarea. </summary>
        public Textarea AddTextarea(int id, int column)
        {
            FormElement sibling = this.LastElement();

            // Default
            Textarea element = new Textarea
            {
                Id       = id,
                Index    = (sibling != null ? sibling.Index + 1 : 0),
                Visible  = true,
                Column   = column,
                Required = false
            };

            this.AddFormElement(element);

            return(element);
        }
Exemple #3
0
        /// <summary> Sets the defaults values as active values. </summary>
        public void PersistDefaultValues()
        {
            List <FormElement> fields = this.GetAllElements();

            foreach (FormElement field in fields)
            {
                if (field is Input)
                {
                    Input f = (field as Input);
                    if (string.IsNullOrEmpty(f.Value))
                    {
                        f.Value = f.DefaultValue;
                    }
                }
                else if (field is Textarea)
                {
                    Textarea f = (field as Textarea);
                    if (string.IsNullOrEmpty(f.Value))
                    {
                        f.Value = f.DefaultValue;
                    }
                }
                else if (field is Calendar)
                {
                    Calendar f = (field as Calendar);
                    if (string.IsNullOrEmpty(f.Value))
                    {
                        f.Value = f.DefaultDate;
                    }
                }
                else if (field is Hidden)
                {
                    Hidden f = (field as Hidden);
                    if (string.IsNullOrEmpty(f.Value))
                    {
                        f.Value = f.DefaultValue;
                    }
                }
                else if (field is Radiobutton)
                {
                    Radiobutton f = (field as Radiobutton);
                    //if (string.IsNullOrEmpty(f.Value)) { f.Value = f.DefaultValue; }
                    if (f.Value.IsNullOrEmpty() && !f.Items.IsNullOrEmpty() && f.Items.Any(x => x.Selected))
                    {
                        f.Value = f.Items.FirstOrDefault(x => x.Selected).Value;
                    }
                }
                else if (field is Checkbox)
                {
                    Checkbox f = (field as Checkbox);
                    if (f.Value.IsNullOrEmpty() && !f.Items.IsNullOrEmpty())
                    {
                        f.Value = f.Items.Where(x => x.Selected).Select(x => x.Value).ToArray();
                    }
                }
                else if (field is Dropdown)
                {
                    Dropdown f = (field as Dropdown);
                    if (f.Value.IsNullOrEmpty() && !f.Items.IsNullOrEmpty())
                    {
                        f.Value = f.Items.Where(x => x.Selected).Select(x => x.Value).ToArray();
                    }
                }
            }
        }
Exemple #4
0
        /// <summary> Get Form Value. </summary>
        /// <param name="formLayoutId"> The form layout id. </param>
        public object GetValue(int formLayoutId)
        {
            IEnumerable <FormElement> elements = GetAllElements();

            FormElement element = elements.Where(x => x.Id == formLayoutId).FirstOrDefault();

            if (element == null)
            {
                return(null);
            }

            if (element.Type == FormElementType.Block)
            {
            }
            else if (element.Type == FormElementType.Html)
            {
                HtmlElement html = element as HtmlElement;

                return(html.Value);
            }
            else if (element.Type == FormElementType.Input)
            {
                Input input = element as Input;

                return(input.Value);
            }
            else if (element.Type == FormElementType.Textarea)
            {
                Textarea textarea = element as Textarea;

                return(textarea.Value);
            }
            else if (element.Type == FormElementType.Dropdown)
            {
                Dropdown dropdown = element as Dropdown;

                return(dropdown.Value);
            }
            else if (element.Type == FormElementType.Radiobutton)
            {
                Radiobutton radio = element as Radiobutton;

                return(radio.Value);
            }
            else if (element.Type == FormElementType.Checkbox)
            {
                Checkbox checkbox = element as Checkbox;

                return(checkbox.Value);
            }
            else if (element.Type == FormElementType.Calendar)
            {
                Calendar calendar = element as Calendar;

                return(calendar.Value);
            }
            else if (element.Type == FormElementType.Hidden)
            {
                Hidden hidden = element as Hidden;

                return(hidden.Value);
            }
            else if (element.Type == FormElementType.Link)
            {
                return((element as Link).GetElementValue());
            }

            return(null);
        }
Exemple #5
0
        /// <summary> Set Form Value. </summary>
        /// <param name="elementId"> The form element id. </param>
        /// <param name="typeId"> The form element type id. </param>
        /// <param name="value"> The form value. </param>
        public void SetValue(int formLayoutId, object value)
        {
            IEnumerable <FormElement> elements = GetAllElements();

            FormElement element = elements.Where(x => x.Id == formLayoutId).FirstOrDefault();

            if (element == null)
            {
                return;
            }

            if (element.Type == FormElementType.Block)
            {
            }
            else if (element.Type == FormElementType.Html)
            {
                HtmlElement html = element as HtmlElement;

                html.Value = Convert.ToString(value);
            }
            else if (element.Type == FormElementType.Input)
            {
                Input input = element as Input;

                input.Value = Convert.ToString(value);
            }
            else if (element.Type == FormElementType.Textarea)
            {
                Textarea textarea = element as Textarea;

                textarea.Value = Convert.ToString(value);
            }
            else if (element.Type == FormElementType.Dropdown)
            {
                Dropdown dropdown = element as Dropdown;

                // Vast value to string array
                string[] valueArray = null;

                if (value != null)
                {
                    Type valueType         = value.GetType();
                    Type genType           = valueType.IsGenericType ? valueType.GetGenericTypeDefinition() : null;
                    bool valueIsEnumerable = valueType.IsArray || (genType != null && (genType == typeof(List <>) || genType == typeof(IEnumerable <>)));

                    if (valueIsEnumerable)
                    {
                        valueArray = ((IEnumerable)value).Cast <object>().Select(x => x.ToString()).ToArray();
                    }
                    else
                    {
                        string sValue = Convert.ToString(value);
                        if (sValue != null)
                        {
                            valueArray = new string[] { sValue };
                        }
                    }
                }

                // Dropdown with items, or ajax source
                if (dropdown.Items != null && dropdown.Items.Count > 0)
                {
                    // Deselect every item
                    foreach (DropdownItem itemX in dropdown.Items)
                    {
                        itemX.Selected = false;
                    }

                    // Values set?
                    if (valueArray != null)
                    {
                        // Valid item placeholder
                        List <string> validItems = new List <string>();

                        // Loop over every value in the value array
                        foreach (string val in valueArray)
                        {
                            // Select item
                            DropdownItem item = dropdown.Items.Where(x => x.Value != null && x.Value.Equals(val, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();

                            // Check if selected item exists
                            if (item != null)
                            {
                                item.Selected = true;
                                validItems.Add(item.Value);
                            }
                        }

                        // Set dropdown value
                        dropdown.Value = validItems.ToArray();
                    }
                }
                else
                {
                    // No items, maybe it's an ajax source
                    if (dropdown.AjaxSource != null)
                    {
                        dropdown.Value = valueArray;
                    }
                }
            }
            else if (element.Type == FormElementType.Radiobutton)
            {
                Radiobutton radio = element as Radiobutton;

                string sValue = Convert.ToString(value);

                RadiobuttonItem item = radio.Items.Where(x => x.Value.Equals(sValue, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();

                if (item != null)
                {
                    foreach (RadiobuttonItem itemX in radio.Items)
                    {
                        itemX.Selected = false;
                    }

                    item.Selected = true;

                    radio.Value = sValue;
                }
            }
            else if (element.Type == FormElementType.Checkbox)
            {
                Checkbox checkbox = element as Checkbox;

                // Vast value to string array
                string[] valueArray = null;
                Type     valueType  = value.GetType();
                if (valueType.IsArray)
                {
                    valueArray = ((IEnumerable)value).Cast <object>().Select(x => x.ToString()).ToArray();
                }
                else
                {
                    string sValue = Convert.ToString(value);
                    valueArray = new string[] { sValue };
                }

                // Deselect every item
                foreach (CheckboxItem itemX in checkbox.Items)
                {
                    itemX.Selected = false;
                }

                // Values set?
                if (valueArray != null)
                {
                    // Valid item placeholder
                    List <string> validItems = new List <string>();

                    // Loop over every value in the value array
                    foreach (string val in valueArray)
                    {
                        CheckboxItem item = checkbox.Items.Where(x => x.Value.Equals(val, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();

                        if (item != null)
                        {
                            item.Selected = true;
                            validItems.Add(item.Value);
                        }
                    }

                    // Set checkbox value
                    checkbox.Value = validItems.ToArray();
                }
            }
            else if (element.Type == FormElementType.Calendar)
            {
                Calendar calendar = element as Calendar;
                calendar.SetElementValue(value);
            }
            else if (element.Type == FormElementType.Hidden)
            {
                Hidden hidden = element as Hidden;

                hidden.Value = Convert.ToString(value);
            }
            else if (element.Type == FormElementType.Tagging)
            {
                Tagging tagging = element as Tagging;

                tagging.Value = (List <TaggingItem>)value;
            }
            else if (element.Type == FormElementType.Link)
            {
                Link obj = element as Link;

                obj.SetElementValue(value);
            }
            else if (element.Type == FormElementType.Label)
            {
                Label label = element as Label;
                label.SetElementValue(value);
            }
        }