public static bool RequireValues(this InputFieldType fieldType)
        {
            switch (fieldType)
            {
            case InputFieldType.Text:
            case InputFieldType.TextArea:
            case InputFieldType.Wyswyg:
            case InputFieldType.Number:
            case InputFieldType.Email:
            case InputFieldType.DateTime:
            case InputFieldType.ImageUpload:
            case InputFieldType.FileUpload:
            case InputFieldType.Hidden:
                return(false);

            case InputFieldType.CheckBox:
            case InputFieldType.RadioButton:
            case InputFieldType.Color:
            case InputFieldType.Dropdown:
                return(true);

            default:
                return(false);
            }
        }
        /// <summary>
        /// Inserts a new input field
        /// </summary>
        /// <param name="fieldName">The name of the new field</param>
        /// <param name="formName">THe name of the form the field would be added</param>
        /// <param name="type">The type of the field</param>
        public void InsertInputField(string fieldName, string formName, InputFieldType type, string formValue)
        {
            string fieldType = string.Empty;

            switch (type)
            {
            case InputFieldType.Button:
                fieldType = "button";
                break;

            case InputFieldType.Password:
                fieldType = "password";
                break;

            case InputFieldType.Submit:
                fieldType = "submit";
                break;

            case InputFieldType.Text:
                fieldType = "text";
                break;
            }

            IHTMLFormElement form = this.GetElementByName(formName) as IHTMLFormElement;

            (form as IHTMLElement).innerHTML += "<input type=\"" + fieldType +
                                                "\" name=\"" + fieldName + "\" style=\"position: absolute\"" +
                                                "value=\"" + formValue + "\" />";
            MakeInsertedElementMovable();
        }
Exemple #3
0
 public InputField(Point pos, string preText, InputFieldController ctor, InputFieldType InputType)
 {
     startPos  = pos;
     PreText   = preText;
     TabId     = ++ctor.TabIdMax;
     inputType = InputType;
     Text      = "";
 }
 private void btnOk_Click(object sender, EventArgs e)
 {
     try
     {
         string         formName  = this.FormName;
         string         fieldName = this.FieldName;
         InputFieldType type      = this.FieldType;
         string         value     = this.FieldValue;
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         this.DialogResult = DialogResult.None;
     }
 }
Exemple #5
0
        public void ShowPopup(bool show, InputFieldType type, string text, EventHandler onOkayClicked = null, EventHandler onCancelClicked = null)
        {
            _informationLabel.text = text;

            _inputField.gameObject.SetActive(type == InputFieldType.Single);
            _inputField1.gameObject.SetActive(type == InputFieldType.Duo);
            _inputField2.gameObject.SetActive(type == InputFieldType.Duo);

            if (onOkayClicked != null)
            {
                OnOkayButtonPressedEventHandler += onOkayClicked;
            }

            if (onCancelClicked != null)
            {
                OnCancelButtonPressedEventHandler += onCancelClicked;
            }

            gameObject.SetActive(show);
        }
        /// <summary>
        /// Inserts a new input field
        /// </summary>
        /// <param name="fieldName">The name of the new field</param>
        /// <param name="formName">THe name of the form the field would be added</param>
        /// <param name="type">The type of the field</param>
        public void InsertInputField(string fieldName, string formName, InputFieldType type, string formValue)
        {
            string fieldType = string.Empty;
            switch (type)
            {
                case InputFieldType.Button:
                    fieldType = "button";
                    break;

                case InputFieldType.Password:
                    fieldType = "password";
                    break;

                case InputFieldType.Submit:
                    fieldType = "submit";
                    break;

                case InputFieldType.Text:
                    fieldType = "text";
                    break;
            }

            IHTMLFormElement form = this.GetElementByName(formName) as IHTMLFormElement;
            (form as IHTMLElement).innerHTML += "<input type=\"" + fieldType +
                                        "\" name=\"" + fieldName + "\" style=\"position: absolute\"" +
                                        "value=\"" + formValue + "\" />";
            MakeInsertedElementMovable();
        }
        /// <summary>
        /// Builds a text input element for each element in the enum-based model property using its enum property as a key
        /// </summary>
        /// <typeparam name="TModel">Model type</typeparam>
        /// <typeparam name="TCollectionItem">Type of the property of the model which to render the inputs for</typeparam>
        /// <typeparam name="TEnumProperty">Type of enum property that's used as a key</typeparam>
        /// <param name="helper"></param>
        /// <param name="collectionPropertyExpression">Collection property of the model which to render the inputs for</param>
        /// <param name="enumPropertyExpression">Property of Enum type that's used as an identifying key for the object and is hidden in the form</param>
        /// <param name="valuePropertyExpression">Property to build the inputs for</param>
        /// <param name="cssClasses">Object that contains css class names for elements built by this helper</param>
        /// <param name="inputFieldType">Type of value input fields</param>
        /// <returns></returns>
        public static MvcHtmlString EditorForEnumBasedCollection <TModel, TCollectionItem, TEnumProperty>(this HtmlHelper <TModel> helper, Expression <Func <TModel, IList <TCollectionItem> > > collectionPropertyExpression, Expression <Func <TCollectionItem, TEnumProperty> > enumPropertyExpression, Expression <Func <TCollectionItem, object> > valuePropertyExpression, CssClasses cssClasses, InputFieldType inputFieldType) where TModel : Content.Base where TEnumProperty : struct, IConvertible, IComparable, IFormattable
        //This TEnumProperty constraint is supposed to ensure that only Enum types are passed
        {
            TModel model = helper.ViewData.Model;

            MemberInfo         enumProperty           = Reflection.Reflection.GetMemberInfo(enumPropertyExpression);
            MemberInfo         valueProperty          = Reflection.Reflection.GetMemberInfo(valuePropertyExpression);
            IList <MemberInfo> collectionPropertyTree = Reflection.Reflection.GetMemberInfoRecursive(collectionPropertyExpression); //Ordered list that contains all properties that lead from TModel type to the target property
            string             propertyQualifiedName  = collectionPropertyTree.JoinValues(item => item.Name, '.');                  // String.Join(".", collectionPropertyTree);// Reflection.GenerateFullPropertyName(collectionPropertyTree);
            string             keyPropertyName        = enumProperty.Name;
            string             valuePropertyName      = valueProperty.Name;

            IList <object> enumValues = GetEnumPropertyValues(enumProperty);                      //All values of the supplied Enum type
            IDictionary <object, object> modelPropertyValues = new Dictionary <object, object>(); //Values that the model's TCollectionItem collection property contains

            //Get all values from model's TCollectionItem collection property
            if (model != null)
            {
                IList <TCollectionItem> modelValues = GetCollectionPropertyValues <TModel, TCollectionItem>(model, collectionPropertyTree);
                foreach (TCollectionItem item in modelValues)
                {
                    object key   = Reflection.Reflection.GetPropertyValue <TCollectionItem>(item, enumProperty);
                    object value = Reflection.Reflection.GetPropertyValue <TCollectionItem>(item, valueProperty);
                    modelPropertyValues.Add(key, value);
                }
            }

            StringBuilder output = new StringBuilder();

            foreach (var item in enumValues)
            {
                string value = null;

                //Get model's value for this enumeration value
                if (model != null)
                {
                    if (modelPropertyValues.ContainsKey(item))
                    {
                        value = (string)modelPropertyValues[item];
                    }
                }

                int id = (int)item;
                output.AppendLine($"<div{GetHtmlClassString(cssClasses?.RootContainerClass)}>");

                MvcHtmlString htmlLabel = helper.Label($"{propertyQualifiedName}[{id}].{valuePropertyName}", item.ToString(), new { @class = cssClasses?.InputLabelClass });

                output.AppendLine(htmlLabel.ToHtmlString());

                output.AppendLine($"<div{GetHtmlClassString(cssClasses?.InputContainerClass)}>");

                MvcHtmlString htmlKey = helper.Hidden($"{propertyQualifiedName}[{id}].{keyPropertyName}", id);

                string valueInputHtml;
                string valueInputName           = $"{propertyQualifiedName}[{id}].{valuePropertyName}";
                object valueInputHtmlAttributes = new { @class = cssClasses?.InputClass, check_for_val = "true" };
                //check_for_val is an attribute that tells to check this input element's value when checking if model is empty on the client side using Javascript

                if (inputFieldType == InputFieldType.TextArea || inputFieldType == InputFieldType.TextAreaModal)
                {
                    if (inputFieldType == InputFieldType.TextAreaModal)
                    {
                        MvcHtmlString input   = helper.TextArea(valueInputName, value, new { @class = cssClasses?.InputClass });
                        string        modalId = EscapeDots($"modal_{propertyQualifiedName}{id}");

                        MvcHtmlString ModalOpenButton = helper.ModalOpenButton(modalId, "Edit");
                        MvcHtmlString modal           = helper.ModalDialog(modalId, input, item.ToString());
                        valueInputHtml = ModalOpenButton.ToString() + modal.ToString();
                    }
                    else
                    {
                        valueInputHtml = helper.TextArea(valueInputName, value, valueInputHtmlAttributes).ToHtmlString();
                    }
                }
                else
                {
                    //helper.ViewContext.ViewData.TemplateInfo.HtmlFieldPrefix contains model name info
                    valueInputHtml = helper.EditorFor(m => value, null, valueInputName, new { htmlAttributes = valueInputHtmlAttributes }).ToString();
                }

                output.AppendLine(htmlKey.ToHtmlString());
                output.AppendLine(valueInputHtml);

                output.AppendLine("</div></div>");
            }
            return(new MvcHtmlString(output.ToString()));
        }
Exemple #8
0
        /// <summary>
        /// Sets the value of an input field.
        /// </summary>
        /// <param name="driver">this</param>
        /// <param name="inputFieldSelector">The selector for the input field to populate.</param>
        /// <param name="inputFieldType">The InputFieldType of the input field.</param>
        /// <param name="value">The value with which to populate the specified input field.</param>
        public static void SetInputFieldValue(this IWebDriver driver, By inputFieldSelector, InputFieldType inputFieldType, string value)
        {
            driver.ScrollIntoView(inputFieldSelector);
            var inputField = RetryPolicies.HandleDriverException().Execute(() => driver.FindElement(inputFieldSelector));

            switch (inputFieldType)
            {
            case InputFieldType.Text:
            case InputFieldType.Password:
                inputField.Clear();
                inputField.SendKeys(value);
                break;

            case InputFieldType.Dropdown:
            case InputFieldType.MultiSelectBox:
                var selectElement = new SelectElement(inputField);
                selectElement.SelectByText(value);
                break;

            case InputFieldType.Checkbox:
            case InputFieldType.RadioButton:
                var currentValue = inputField.Selected ? "true" : "false";
                if (!currentValue.Equals(value, StringComparison.InvariantCultureIgnoreCase))
                {
                    inputField.Click();
                }
                break;

            default:
                throw new ArgumentOutOfRangeException($"{inputFieldType} is not a valid input field type.");
            }
        }
Exemple #9
0
        /// <summary>
        /// Returns the current value of a given input field.
        /// </summary>
        /// <param name="driver">this</param>
        /// <param name="inputFieldSelector">The selector for the input field to pull the current value from.</param>
        /// <param name="inputFieldType">The InputFieldType of the input field.</param>
        /// <returns>The current value of the specified input field.</returns>
        public static string GetInputFieldValue(this IWebDriver driver, By inputFieldSelector, InputFieldType inputFieldType)
        {
            driver.ScrollIntoView(inputFieldSelector);
            var inputField = RetryPolicies.HandleDriverException().Execute(() => driver.FindElement(inputFieldSelector));

            switch (inputFieldType)
            {
            case InputFieldType.Text:
            case InputFieldType.Password:
                return(inputField.GetAttribute("value"));

            case InputFieldType.Dropdown:
            case InputFieldType.MultiSelectBox:
                var selectElement = new SelectElement(inputField);
                return(selectElement.SelectedOption.Text);

            case InputFieldType.Checkbox:
            case InputFieldType.RadioButton:
                return(inputField.Selected ? "true" : "false");

            default:
                throw new ArgumentOutOfRangeException($"{inputFieldType} is not a valid input field type.");
            }
        }
Exemple #10
0
        /// <summary>
        /// Returns the current value(s) of a given input field.
        /// </summary>
        /// <param name="driver">this</param>
        /// <param name="inputFieldSelector">The selector for the input field to pull the current value(s) from.</param>
        /// <param name="inputFieldType">The InputFieldType of the input field.</param>
        /// <returns>A list of the current value(s) of the specified input field. All input field types other than a Multi-Select Box will return a list with a single entry.</returns>
        public static List <string> GetInputFieldValues(this IWebDriver driver, By inputFieldSelector, InputFieldType inputFieldType)
        {
            driver.ScrollIntoView(inputFieldSelector);

            if (inputFieldType == InputFieldType.MultiSelectBox)
            {
                var inputField = RetryPolicies.HandleDriverException().Execute(() => driver.FindElement(inputFieldSelector));
                return(new SelectElement(inputField).Options.Select(x => x.Text).ToList());
            }

            return(new List <string> {
                GetInputFieldValue(driver, inputFieldSelector, inputFieldType)
            });
        }