Esempio n. 1
0
 protected FormElementViewModel(FormElement formElement)
 {
     FormElement   = formElement;
     Name          = formElement.Name;
     Label         = formElement.Label;
     LabelPosition = formElement.LabelPosition;
 }
        public override void GetElementValue(FormElement element, ReadElementValuesContext context)
        {
            if (String.IsNullOrWhiteSpace(element.Name))
            {
                return;
            }

            var key = element.Name;
            var valueProviderResult = context.ValueProvider.GetValue(key);

            if (String.IsNullOrWhiteSpace(key) || valueProviderResult == null)
            {
                return;
            }

            var items = valueProviderResult.RawValue as string[];

            if (items == null)
            {
                return;
            }

            var combinedValues = String.Join(",", items);

            context.Output[key]  = combinedValues;
            element.RuntimeValue = combinedValues;
            element.PostedValue  = combinedValues;
        }
Esempio n. 3
0
        public string RenderLabel(FormElement formElement, IFormBuilderParameters formBuilderParameters)
        {
            var sb           = new StringBuilder();
            var stringWriter = new StringWriter(sb);
            var textWriter   = new HtmlTextWriter(stringWriter);

            var bootStrapBuilderParameters = (BuilderParameters)formBuilderParameters;
            // if there is a Name specified in the DisplayAttribute use it , other wise use the property name
            var displayName = formElement.ControlSpecs.ControlName.SpacePascal();

            if (!String.IsNullOrEmpty(formElement.ControlSpecs.Name))
            {
                displayName = formElement.ControlSpecs.Name;
            }

            // Label
            if (bootStrapBuilderParameters.FormType == BootstrapFormType.Horizontal)
            {
                textWriter.AddAttribute(HtmlTextWriterAttribute.Class, "col-lg-3 control-label");
            }
            else
            {
                textWriter.AddAttribute(HtmlTextWriterAttribute.Class, "control-label");
            }

            textWriter.AddAttribute(HtmlTextWriterAttribute.For, formElement.ControlSpecs.ControlName);
            textWriter.RenderBeginTag(HtmlTextWriterTag.Label);
            textWriter.Write(displayName);
            textWriter.RenderEndTag(); // label
            return(sb.ToString());
        }
Esempio n. 4
0
 public List<FormElement> GetOptions(HtmlNode htmlNode)
 {
     List<FormElement> options = new List<FormElement>();
     HtmlNodeCollection nodeTags = htmlNode.SelectNodes(@".//option");
     if (nodeTags != null)
     {
         foreach (HtmlNode node in nodeTags)
         {
             string id = node.GetAttributeValue("id", "");
             string type = "option";
             string name = node.GetAttributeValue("name", "");
             string value = node.GetAttributeValue("value", "");
             bool chk = node.Attributes["selected"] != null;
             FormElement el = new FormElement();
             el.Id = id;
             el.Type = type;
             el.Name = node.NextSibling.InnerText;
             el.Value = value;
             el.Type = type;
             el.Checked = chk;
             options.Add(el);
         }
     }
     return options;
 }
Esempio n. 5
0
 private void 生成试验组_Load(object sender, EventArgs e)
 {
     if (_form == null)
     {
         _form = new FormElement();
     }
     _form.LoadTabs(new string[] { "dbo.生成试验组" }, new decimal[] { -1 });
     _form.AddControlByLayout(this.panel_试验日期, "dbo.生成试验组", "试验日期");
     _form.AddControlByLayout(this.panel_试验组名, "dbo.生成试验组", "试验组名");
     _form.AddControlByLayout(this.panel_试验编号, "dbo.生成试验组", "试验编号");
     //-----------------add室温--------------begin
     _form.AddControlByLayout(this.panel_室温, "dbo.生成试验组", "室温");
     //---------------- add 室温------------end
     _form.AddControlByLayout(this.panel_水温, "dbo.生成试验组", "水温");
     _form.AddControlByLayout(this.panel_气压, "dbo.生成试验组", "气压");
     _form.AddControlByLayout(this.panel_被试水泵, "dbo.生成试验组", "被试水泵ID");
     _form.AddControlByLayout(this.panel_拖动电机, "dbo.生成试验组", "拖动电机ID");
     _form.AddControlByLayout(this.panel_流量仪表, "dbo.生成试验组", "流量仪表ID");
     _form.AddControlByLayout(this.panel_转速测量, "dbo.生成试验组", "转速测量ID");
     _form.AddControlByLayout(this.panel_进口压力仪表, "dbo.生成试验组", "进口压力仪表ID");
     _form.AddControlByLayout(this.panel_出口压力仪表, "dbo.生成试验组", "出口压力仪表ID");
     _form.AddControlByLayout(this.panel_功率测量仪表, "dbo.生成试验组", "功率测量仪表ID");
     _form.AddControlByLayout(this.panel_温度测量仪表, "dbo.生成试验组", "温度测量仪表ID");
     _form.AddControlByLayout(this.panel_液力耦合器, "dbo.生成试验组", "液力耦合器ID");
     查询_试验组数据();
     刷新控件数据();
 }
Esempio n. 6
0
        internal static string SerializeForm(FormElement form)
        {
            DOMElement[]  formElements = form.Elements;
            StringBuilder formBody     = new StringBuilder();

            int count = formElements.Length;

            for (int i = 0; i < count; i++)
            {
                DOMElement element = formElements[i];
                string     name    = (string)Type.GetField(element, "name");
                if (name == null || name.Length == 0)
                {
                    continue;
                }

                string tagName = element.TagName.ToUpperCase();

                if (tagName == "INPUT")
                {
                    InputElement inputElement = (InputElement)element;
                    string       type         = inputElement.Type;
                    if ((type == "text") ||
                        (type == "password") ||
                        (type == "hidden") ||
                        (((type == "checkbox") || (type == "radio")) && (bool)Type.GetField(element, "checked")))
                    {
                        formBody.Append(name.EncodeURIComponent());
                        formBody.Append("=");
                        formBody.Append(inputElement.Value.EncodeURIComponent());
                        formBody.Append("&");
                    }
                }
                else if (tagName == "SELECT")
                {
                    SelectElement selectElement = (SelectElement)element;
                    int           optionCount   = selectElement.Options.Length;
                    for (int j = 0; j < optionCount; j++)
                    {
                        OptionElement optionElement = (OptionElement)selectElement.Options[j];
                        if (optionElement.Selected)
                        {
                            formBody.Append(name.EncodeURIComponent());
                            formBody.Append("=");
                            formBody.Append(optionElement.Value.EncodeURIComponent());
                            formBody.Append("&");
                        }
                    }
                }
                else if (tagName == "TEXTAREA")
                {
                    formBody.Append(name.EncodeURIComponent());
                    formBody.Append("=");
                    formBody.Append(((string)Type.GetField(element, "value")).EncodeURIComponent());
                    formBody.Append("&");
                }
            }

            return(formBody.ToString());
        }
        public IActionResult Post(FormElement data)
        {
            data.isActive = true;
            var createdAbout = service.Add(data);

            return(CreatedAtAction("Get", new { id = createdAbout.Data.Id }, createdAbout));
        }
Esempio n. 8
0
        public static void HandleSubmit(FormElement form, DomEvent evt, AjaxOptions ajaxOptions)
        {
            evt.PreventDefault();

            // run validation
            ArrayList validationCallbacks = (ArrayList)Type.GetField(form, "validationCallbacks");

            if (validationCallbacks != null)
            {
                for (int i = 0; i < validationCallbacks.Length; i++)
                {
                    ValidationCallback callback = (ValidationCallback)validationCallbacks[i];
                    if (!callback())
                    {
                        return; // bail out since validation failed
                    }
                }
            }

            string body = MvcHelpers.SerializeForm(form);

            MvcHelpers.AsyncRequest(form.Action,
                                    form.Method ?? "post",
                                    body,
                                    form,
                                    ajaxOptions);
        }
        private TagBuilder RenderEnum(FormElement formElement)
        {
            var value      = formElement.FieldValue;
            var tagbuilder = new TagBuilder("select");


            foreach (var enumValue in Enum.GetValues(formElement.MappedDataType))
            {
                var option = new TagBuilder("option");
                option.MergeAttribute(HtmlAtrributes.Value, enumValue.ToString());

                var enumValueText = EnumExtensions.GetEnumDescription((Enum)enumValue);
                option.SetInnerText(enumValueText);
                var selected = value != null && (int)enumValue == (int)Enum.Parse(formElement.MappedDataType, value.ToString());

                if (selected)
                {
                    option.MergeAttribute(HtmlAtrributes.Selected, null);
                }

                tagbuilder.InnerHtml += option.ToMvcHtmlString(TagRenderMode.Normal);
            }

            tagbuilder.MergeAttribute("id", formElement.ControlSpecs.ClientId);
            tagbuilder.MergeAttribute(HtmlAtrributes.Name, formElement.ControlSpecs.ControlName);
            return(tagbuilder);
        }
Esempio n. 10
0
    public override FormInput Title()
    {
        int[] faceIds = measure.face.ids;
        int   len     = faceIds.Length;

        FormElement formElement = new FormElement(len);

        for (int i = 0; i < len; i++)
        {
            formElement.fields[i] = geometry.VertexSign(faceIds[i]);
        }

        float   area    = geometry.FaceArea(faceIds);
        FormNum formNum = new FormNum(area);

        formNum.format = UIConstants.AreaFormat;

        FormInput formInput = new FormInput(4);

        formInput.inputs[0] = formElement;
        formInput.inputs[1] = new FormText("面积");
        formInput.inputs[2] = new FormText("=");
        formInput.inputs[3] = formNum;

        return(formInput);
    }
Esempio n. 11
0
    public override Auxiliary GenerateAuxiliary(Geometry geometry, FormInput formInput)
    {
        bool valid = ValidateInput(geometry, formInput);

        if (!valid)
        {
            return(null);
        }

        FormElement formElement1 = (FormElement)formInput.inputs[1];
        FormElement formElement2 = (FormElement)formInput.inputs[3];
        int         id1          = geometry.SignVertex(formElement1.fields[0]);

        string[] fields = formElement2.fields;
        int[]    ids    = new int[fields.Length];
        for (int i = 0; i < fields.Length; i++)
        {
            ids[i] = geometry.SignVertex(fields[i]);
        }

        FormElement            SignElement = (FormElement)formInput.inputs[6];
        string                 sign        = Sign(SignElement);
        PlaneVerticalAuxiliary auxiliary   = new PlaneVerticalAuxiliary(id1, ids, sign);

        return(auxiliary);
    }
Esempio n. 12
0
    public override FormInput Title()
    {
        int[] faceIds = auxiliary.face.ids;
        int   len     = faceIds.Length;

        FormElement formElement1 = new FormElement(len);

        for (int i = 0; i < len; i++)
        {
            formElement1.fields[i] = geometry.VertexSign(faceIds[i]);
        }

        FormElement formElement2 = new FormElement(2);

        formElement2.fields[0] = geometry.VertexSign(auxiliary.vertex.id);
        formElement2.fields[1] = geometry.VertexSign(auxiliary.units[0].id);

        FormInput formInput = new FormInput(3);

        formInput.inputs[0] = formElement1;
        formInput.inputs[1] = new FormText("的垂线");
        formInput.inputs[2] = formElement2;

        return(formInput);
    }
Esempio n. 13
0
        private string CreateAttackVector(XAttackParam[] attackParams, Form form)
        {
            string postData = "";

            for (int i = 0; i < form.FormElements.Count; i++)
            {
                FormElement element = form.FormElements.ElementAt(i);

                if (!(form.Method == "get" && element.Type == "submit"))
                {
                    postData += string.Format("{0}={1}&", element.Name, HttpUtility.UrlEncode(attackParams[i].Value));
                }
            }

            postData = postData.Substring(0, postData.Length - 1);

            if (form.Method == "get")
            {
                postData = "?" + postData;
            }

            if (form.Method == "get" && !form.Action.EndsWith("/"))
            {
                postData = "/" + postData;
            }

            return(postData);
        }
Esempio n. 14
0
        private XAttackParam[] ComputeAttackParams(Form form)
        {
            List <XAttackParam> lstParams = new List <XAttackParam>();

            for (int i = 0; i < form.FormElements.Count; i++)
            {
                FormElement element = form.FormElements.ElementAt(i);

                if (element.Type == "hidden")
                {
                    lstParams.Add(new XAttackParam()
                    {
                        Value = element.Value, FormElementId = element.Id
                    });
                }
                else if (element.Type == "text" ||
                         element.Type == "password" ||
                         element.Type == "email")
                {
                    lstParams.Add(new XAttackParam()
                    {
                        Value = GetInjectionValue(), FormElementId = element.Id
                    });
                }
                else
                {
                    lstParams.Add(new XAttackParam()
                    {
                        Value = "", FormElementId = element.Id
                    });
                }
            }

            return(lstParams.ToArray());
        }
Esempio n. 15
0
        //--cloning--//
        public override FormElement Clone()
        {
            FormElement inner = this.formElement.Clone();
            GridElement clone = new GridElement(inner, this.col, this.row, this.colSpan, this.rowSpan, this.isBordered);

            return(clone);
        }
Esempio n. 16
0
    public FormElement VertexForm(GeoVertex vertex)
    {
        string      s           = geometry.VertexSign(vertex.Id);
        FormElement formElement = new FormElement(1, new string[] { s });

        return(formElement);
    }
Esempio n. 17
0
        public static IFormElementViewModel Create(FormElement model)
        {
            switch (model)
            {
            //Layouts
            case CompositeElement compositeElement:
                return(CreateComposite(compositeElement));

            //Controls
            case HtmlElement htmlElement:
                return(new HtmlElementViewModel(htmlElement));

            case ButtonElement buttonElement:
                return(new ButtonElementViewModel(buttonElement));

            //Fields
            case TextElement textField:
                return(new TextElementViewModel(textField));

            case SelectElement comboBoxField:
                return(new SelectElementViewModel(comboBoxField));

            case CheckElement checkBoxField:
                return(new CheckElementViewModel(checkBoxField));

            default:
                return(new NullElementViewModel());
            }
        }
Esempio n. 18
0
    public void RefreshForm(FormInput formInput)
    {
        if (formInput != form)
        {
            return;
        }

        FormItem[] inputs = form.inputs;
        for (int i = 0; i < inputs.Length; i++)
        {
            if (inputs[i] is FormElement)
            {
                FormElement  formElement  = (FormElement)inputs[i];
                InputElement inputElement = (InputElement)inputBases[i];
                inputElement.Refresh(formElement);
            }
            else if (inputs[i] is FormNum)
            {
                FormNum  formNum  = (FormNum)inputs[i];
                InputNum inputNum = (InputNum)inputBases[i];
                inputNum.Refresh(formNum);
            }
            else if (inputs[i] is FormText)
            {
                FormText  formText  = (FormText)inputs[i];
                InputText inputText = (InputText)inputBases[i];
                inputText.Refresh(formText);
            }
        }
    }
        private static String RenderElementByType(HtmlHelper html, FormElement model, String elementName, String elementValue)
        {
            var builder = new StringBuilder();
            switch (model.Type)
            {
                case FormElementType.TextField:
                    {
                        builder.Append(html.Encode(model.Title));
                        break;
                    }
                case FormElementType.TextBox:
                    {
                        builder.Append(html.Label(elementName, model.Title));
                        builder.Append("<br/>");
                        builder.Append(html.TextBox(elementName, elementValue));
                        break;
                    }
                case FormElementType.TextArea:
                    {
                        builder.Append(html.Label(elementName, model.Title));
                        builder.Append("<br/>");
                        builder.Append(html.TextArea(elementName, elementValue));
                        break;
                    }
                case FormElementType.CheckBox:
                    {
                        builder.Append(html.SimpleCheckBox(elementName, FormCollectionExtensions.BooleanValue(elementValue)));
                        builder.Append(html.Label(elementName, model.Title));
                        break;
                    }
                case FormElementType.DropDownList:
                    {
                        builder.Append(html.Label(elementName, model.Title));
                        builder.Append("<br/>");
                        builder.Append(html.DropDownList(elementName, ParseElementValuesForDropDown(model.ElementValues, elementValue)));
                        break;
                    }
                case FormElementType.RadioButtons:
                    {
                        builder.Append(html.Label(elementName, model.Title));
                        builder.Append("<br/>");
                        builder.Append(html.RadioList(elementName, ParseElementValuesForRadioButtons(model.ElementValues, elementName), elementValue));
                        break;
                    }
                case FormElementType.Captcha:
                    {
                        builder.Append(html.CaptchaImage(CaptchaDefaultHeight, CaptchaDefaultWidth));
                        builder.Append(html.Label(elementName, String.Empty));
                        builder.Append("<br/>");
                        builder.Append(html.CaptchaTextBox(elementName));
                        break;
                    }

                default:
                    break;
            }

            return builder.ToString();
        }
Esempio n. 20
0
        internal static FormContext ParseJsonOptions(JsonValidationOptions options)
        {
            // First hook up the form logic
            FormElement formElement = (FormElement)Document.GetElementById(options.FormId);
            DOMElement  validationSummaryElement = (!ValidationUtil.StringIsNullOrEmpty(options.ValidationSummaryId))
                ? Document.GetElementById(options.ValidationSummaryId)
                : null;

            FormContext formContext = new FormContext(formElement, validationSummaryElement);

            formContext.EnableDynamicValidation();
            formContext.ReplaceValidationSummary = options.ReplaceValidationSummary;

            // Then hook up the field logic
            for (int i = 0; i < options.Fields.Length; i++)
            {
                JsonValidationField field                    = options.Fields[i];
                DOMElement[]        fieldElements            = GetFormElementsWithName(formElement, field.FieldName);
                DOMElement          validationMessageElement = (!ValidationUtil.StringIsNullOrEmpty(field.ValidationMessageId))
                    ? Document.GetElementById(field.ValidationMessageId)
                    : null;

                FieldContext fieldContext = new FieldContext(formContext);
                ArrayList.AddRange((ArrayList)(object)fieldContext.Elements, fieldElements);
                fieldContext.ValidationMessageElement         = validationMessageElement;
                fieldContext.ReplaceValidationMessageContents = field.ReplaceValidationMessageContents;

                // Hook up rules
                for (int j = 0; j < field.ValidationRules.Length; j++)
                {
                    JsonValidationRule rule      = field.ValidationRules[j];
                    Validator          validator = ValidatorRegistry.GetValidator(rule);
                    if (validator != null)
                    {
                        Validation validation = new Validation();
                        validation.FieldErrorMessage = rule.ErrorMessage;
                        validation.Validator         = validator;
                        ArrayList.Add((ArrayList)(object)fieldContext.Validations, validation);
                    }
                }

                fieldContext.EnableDynamicValidation();
                ArrayList.Add((ArrayList)(object)formContext.Fields, fieldContext);
            }

            // hook up callback so that it can be executed by the AJAX code
            ArrayList registeredValidatorCallbacks = (ArrayList)Type.GetField(formElement, "validationCallbacks");

            if (registeredValidatorCallbacks == null)
            {
                registeredValidatorCallbacks = new ArrayList();
                Type.SetField(formElement, "validationCallbacks", registeredValidatorCallbacks);
            }
            Type.InvokeMethod(registeredValidatorCallbacks, "push", (ValidationCallback) delegate() {
                return(ValidationUtil.ArrayIsNullOrEmpty(formContext.Validate("submit")));
            });

            return(formContext);
        }
        public static void Run()
        {
            // ExStart:CreateStructureElements
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_WorkingDocuments();

            // Create Pdf Document
            Document document = new Document();

            // Get Content for work with TaggedPdf
            ITaggedContent taggedContent = document.TaggedContent;

            // Set Title and Language for Documnet
            taggedContent.SetTitle("Tagged Pdf Document");
            taggedContent.SetLanguage("en-US");

            // Create Grouping Elements
            PartElement       partElement       = taggedContent.CreatePartElement();
            ArtElement        artElement        = taggedContent.CreateArtElement();
            SectElement       sectElement       = taggedContent.CreateSectElement();
            DivElement        divElement        = taggedContent.CreateDivElement();
            BlockQuoteElement blockQuoteElement = taggedContent.CreateBlockQuoteElement();
            CaptionElement    captionElement    = taggedContent.CreateCaptionElement();
            TOCElement        tocElement        = taggedContent.CreateTOCElement();
            TOCIElement       tociElement       = taggedContent.CreateTOCIElement();
            IndexElement      indexElement      = taggedContent.CreateIndexElement();
            NonStructElement  nonStructElement  = taggedContent.CreateNonStructElement();
            PrivateElement    privateElement    = taggedContent.CreatePrivateElement();

            // Create Text Block-Level Structure Elements
            ParagraphElement paragraphElement = taggedContent.CreateParagraphElement();
            HeaderElement    headerElement    = taggedContent.CreateHeaderElement();
            HeaderElement    h1Element        = taggedContent.CreateHeaderElement(1);

            // Create Text Inline-Level Structure Elements
            SpanElement  spanElement  = taggedContent.CreateSpanElement();
            QuoteElement quoteElement = taggedContent.CreateQuoteElement();
            NoteElement  noteElement  = taggedContent.CreateNoteElement();

            // Create Illustration Structure Elements
            FigureElement  figureElement  = taggedContent.CreateFigureElement();
            FormulaElement formulaElement = taggedContent.CreateFormulaElement();

            // Methods are under development
            ListElement      listElement      = taggedContent.CreateListElement();
            TableElement     tableElement     = taggedContent.CreateTableElement();
            ReferenceElement referenceElement = taggedContent.CreateReferenceElement();
            BibEntryElement  bibEntryElement  = taggedContent.CreateBibEntryElement();
            CodeElement      codeElement      = taggedContent.CreateCodeElement();
            LinkElement      linkElement      = taggedContent.CreateLinkElement();
            AnnotElement     annotElement     = taggedContent.CreateAnnotElement();
            RubyElement      rubyElement      = taggedContent.CreateRubyElement();
            WarichuElement   warichuElement   = taggedContent.CreateWarichuElement();
            FormElement      formElement      = taggedContent.CreateFormElement();

            // Save Tagged Pdf Document
            document.Save(dataDir + "StructureElements.pdf");
            // ExEnd:CreateStructureElements
        }
Esempio n. 22
0
 public virtual TBuilder FromTemplate(FormElement element)
 {
     Id   = element.Id;
     Name = element.Name;
     VerticalAlignment   = VerticalAlignment;
     HorizontalAlignment = HorizontalAlignment;
     return(this as TBuilder);
 }
Esempio n. 23
0
 private void  除_转速测量数据()
 {
     if (_form == null)
     {
         _form = new FormElement();
     }
     _form.deleteTabs(new string[] { "dbo.转速测量" });
 }
Esempio n. 24
0
 private void 保存_流量仪表数据()
 {
     if (_form == null)
     {
         _form = new FormElement();
     }
     _form.SaveTabs(new string[] { "dbo.流量仪表" });
 }
Esempio n. 25
0
 private void  除_电机型号管理数据()
 {
     if (_form == null)
     {
         _form = new FormElement();
     }
     _form.deleteTabs(new string[] { "dbo.电机型号管理" });
 }
Esempio n. 26
0
 private void  除_试验组数据()
 {
     if (_form == null)
     {
         _form = new FormElement();
     }
     _form.deleteTabs(new string[] { "dbo.生成试验组" });
 }
Esempio n. 27
0
    public FormElement EdgeForm(GeoEdge edge)
    {
        string      s1          = geometry.VertexSign(edge.Id1);
        string      s2          = geometry.VertexSign(edge.Id2);
        FormElement formElement = new FormElement(2, new string[] { s1, s2 });

        return(formElement);
    }
Esempio n. 28
0
 private void  除_进口压力仪表数据()
 {
     if (_form == null)
     {
         _form = new FormElement();
     }
     _form.deleteTabs(new string[] { "dbo.进口压力仪表" });
 }
Esempio n. 29
0
 private void  除_液力耦合器数据()
 {
     if (_form == null)
     {
         _form = new FormElement();
     }
     _form.deleteTabs(new string[] { "dbo.液力耦合器" });
 }
 protected override void InitializeElement(FormElement element)
 {
     if (element is ContentElement contentElement)
     {
         contentElement.Content     = Utilities.GetStringResource(Value);
         contentElement.IconPadding = Utilities.GetResource <bool>(IconPadding, false, Deserializers.Boolean);
     }
 }
Esempio n. 31
0
        internal static string SerializeForm(FormElement form) {
            DOMElement[] formElements = form.Elements;
            StringBuilder formBody = new StringBuilder();

            int count = formElements.Length;
            for (int i = 0; i < count; i++) {
                DOMElement element = formElements[i];
                string name = (string)Type.GetField(element, "name");
                if (name == null || name.Length == 0) {
                    continue;
                }

                string tagName = element.TagName.ToUpperCase();

                if (tagName == "INPUT") {
                    InputElement inputElement = (InputElement)element;
                    string type = inputElement.Type;
                    if ((type == "text") ||
                        (type == "password") ||
                        (type == "hidden") ||
                        (((type == "checkbox") || (type == "radio")) && (bool)Type.GetField(element, "checked"))) {

                        formBody.Append(name.EncodeURIComponent());
                        formBody.Append("=");
                        formBody.Append(inputElement.Value.EncodeURIComponent());
                        formBody.Append("&");
                    }
                }
                else if (tagName == "SELECT") {
                    SelectElement selectElement = (SelectElement)element;
                    int optionCount = selectElement.Options.Length;
                    for (int j = 0; j < optionCount; j++) {
                        OptionElement optionElement = (OptionElement)selectElement.Options[j];
                        if (optionElement.Selected) {
                            formBody.Append(name.EncodeURIComponent());
                            formBody.Append("=");
                            formBody.Append(optionElement.Value.EncodeURIComponent());
                            formBody.Append("&");
                        }
                    }
                }
                else if (tagName == "TEXTAREA") {
                    formBody.Append(name.EncodeURIComponent());
                    formBody.Append("=");
                    formBody.Append(((string)Type.GetField(element, "value")).EncodeURIComponent());
                    formBody.Append("&");
                }
            }

            // additional input represents the submit button or image that was clicked
            string additionalInput = (string)Type.GetField(form, "_additionalInput");
            if (additionalInput != null) {
                formBody.Append(additionalInput);
                formBody.Append("&");
            }

            return formBody.ToString();
        }
        void IFormElementEventHandler.RegisterClientValidation(FormElement element, RegisterClientValidationAttributesContext context)
        {
            var validators = _formService.GetValidators(element).ToArray();

            foreach (var validator in validators)
            {
                validator.RegisterClientValidation(element, context);
            }
        }
Esempio n. 33
0
        public string EndElementContainer(FormElement formElement, IFormBuilderParameters formBuilderParameters)
        {
            var sb           = new StringBuilder();
            var stringWriter = new StringWriter(sb);
            var textWriter   = new HtmlTextWriter(stringWriter);

            ElementContainer.End(textWriter);
            return(sb.ToString());
        }
        public static void HandleSubmit(FormElement form, DomEvent evt, AjaxOptions ajaxOptions) {
            evt.PreventDefault();
            string body = MvcHelpers.SerializeForm(form);
            MvcHelpers.AsyncRequest(form.Action, 
                                    form.Method ?? "post",
                                    body,
                                    form,
                                    ajaxOptions);

        }
Esempio n. 35
0
        public static FormElement AttributeValueFromFormNode(XElement node)
        {
            var formElement = new FormElement();
            var properties = formElement.GetType().GetProperties();

            foreach (var property in properties)
            {
                var value = ExtractAttributeValueFromNode(property.Name, node);
                property.SetValue(formElement, value, null);
            }

            return formElement;
        }
        /// <summary>
        /// Attaches to the specified visual component as associated object.
        /// </summary>
        /// <param name="component">The object to attach to.</param><exception cref="T:System.InvalidOperationException">Cannot host the same TriggerAction on more than one object at a time.</exception><exception cref="T:System.InvalidOperationException">dependencyObject does not satisfy the TriggerAction type constraint.</exception>
        public void Attach(Component component)
        {
            if (component == null)
                throw new NullReferenceException("component");

            if (component == AssociatedObject.HostedComponent)
                return;

            if (AssociatedObject != null)
                throw new InvalidOperationException("Cannot host multiple components.");

            var element = new FormElement(component);
            AssociatedObject = element;
            OnAttached();
        }
 private void AddChildren(FormElement element)
 {
     if (element.Children.Count > 0)
     {
         var expander = new Expander();
         var panel = new FormPanel();
         foreach (var child in element.Children)
         {
             var visitor = new FormElementVisitorImpl();
             visitor.VisitFormElement(child);
             visitor.Result.Margin = new Thickness(20, 0, 0, 0);
             panel.Children.Add(visitor.Result);
         }
         expander.Content = panel;
         _result.Children.Add(expander);
     }
 }
        /// <summary>
        /// Renders html depends on model's type (i.e. textbox, radion buttons)
        /// </summary>
        /// <param name="html">The HTML.</param>
        /// <param name="model">The model.</param>
        /// <param name="collection">The collection.</param>
        /// <returns></returns>
        public static MvcHtmlString FormElementRenderer(this HtmlHelper html, FormElement model, FormCollection collection)
        {
            var builder = new StringBuilder();

            var elementName = String.Format(FormElementNameFormat, model.Type, model.Id);
            var elementValue = String.Empty;
            if (collection!=null && collection[elementName]!=null)
            {
                elementValue = collection[elementName];
            }

            builder.Append(RenderElementByType(html, model, elementName, elementValue));
            builder.Append("<br/>");
            builder.Append(html.ValidationMessage(elementName));
        
            return MvcHtmlString.Create(builder.ToString());
        }
Esempio n. 39
0
        public FormContext(FormElement formElement, DOMElement validationSummaryElement) {
            FormElement = formElement;
            _validationSummaryElement = validationSummaryElement;

            Type.SetField(formElement, _formValidationTag, this);

            // need to retrieve the actual <ul> element, since that will be dynamically modified
            if (validationSummaryElement != null) {
                DOMElementCollection ulElements = validationSummaryElement.GetElementsByTagName("ul");
                if (ulElements.Length > 0) {
                    _validationSummaryULElement = ulElements[0];
                }
            }

            _onClickHandler = Form_OnClick;
            _onSubmitHandler = Form_OnSubmit;
        }
Esempio n. 40
0
        public static XElement AddNodeToForm(Element param)
        {
            var node = new XElement("Form");

            var formElement = new FormElement(param);
            var properties = formElement.GetType().GetProperties();

            foreach (var property in properties)
            {
                var value = property.GetValue(formElement, null);

                if (value != null && !string.IsNullOrEmpty(value.ToString()))
                {
                    AddAttributeInNode(property.Name, value.ToString(), node);
                }
            }

            return node;
        }
Esempio n. 41
0
        public static void HandleSubmit(FormElement form, DomEvent evt, AjaxOptions ajaxOptions) {
            evt.PreventDefault();

            // run validation
            ArrayList validationCallbacks = (ArrayList)Type.GetField(form, "validationCallbacks");
            if (validationCallbacks != null) {
                for (int i = 0; i < validationCallbacks.Length; i++) {
                    ValidationCallback callback = (ValidationCallback)validationCallbacks[i];
                    if (!callback()) {
                        return; // bail out since validation failed
                    }
                }
            }

            string body = MvcHelpers.SerializeForm(form);
            MvcHelpers.AsyncRequest(form.Action, 
                                    form.Method ?? "post",
                                    body,
                                    form,
                                    ajaxOptions);

        }
Esempio n. 42
0
 public List<FormElement> GetProductDetailOptions(HtmlNode htmlNode, string tagId)
 {
     List<FormElement> options = new List<FormElement>();
     HtmlNodeCollection nodeTags = htmlNode.SelectNodes(@".//select[@id='" + tagId + "']/option");
     if (nodeTags != null)
     {
         foreach (HtmlNode node in nodeTags)
         {
             string id = node.GetAttributeValue("id", "");
             string type = "option";
             string name = node.GetAttributeValue("name", "");
             string value = node.GetAttributeValue("value", "");
             FormElement el = new FormElement();
             el.Id = id;
             el.Type = type;
             el.Name = node.NextSibling.InnerText;
             el.Value = value;
             el.Type = type;
             options.Add(el);
         }
     }
     return options;
 }
Esempio n. 43
0
        public ProductDetail PrintElementsValue(HtmlNode htmlNode)
        {
            ProductDetail detail = new ProductDetail();
            Type typeOfClass = detail.GetType();
            IEnumerable<HtmlNode> nodeTags = htmlNode.SelectNodes(@".//input[@type='hidden'] | .//input[@type='text']");
            if (nodeTags != null)
            {
                foreach (HtmlNode node in nodeTags)
                {
                    string id = node.GetAttributeValue("id", "");
                    string type = node.GetAttributeValue("type", "");
                    string name = node.GetAttributeValue("name", "");
                    string value = node.GetAttributeValue("value", "");
                    if ("_fmp.pr._0.u" == name || "_fmp.pr._0.us" == name)
                    {
                        continue;
                    }
                    System.Diagnostics.Trace.WriteLine("Id:" + id + "  type:" + type + "  name:" + name + "  value:" + value);

                    FormElement el = new FormElement();
                    el.Id = id;
                    el.Type = type;
                    el.Name = name;
                    el.Value = value;

                    string propertyName = GetPropertyName(id, name);
                    PropertyInfo pInfo = typeOfClass.GetProperty(propertyName);
                    if (pInfo != null && pInfo.PropertyType.Name == "FormElement")
                    {
                        pInfo.SetValue(detail, el, null);
                    }
                }
            }
            detail.CustomAttr = new Dictionary<FormElement, FormElement>();
            HtmlNodeCollection customNameTags = htmlNode.SelectNodes(@".//tr[@class='custom-attr-item']/td/input[@name='_fmp.pr._0.u']");
            HtmlNodeCollection customValueTags = htmlNode.SelectNodes(@".//tr[@class='custom-attr-item']/td/input[@name='_fmp.pr._0.us']");
            if (customNameTags != null)
            {
                for (int i = 0; i < customNameTags.Count; i ++ )
                {
                    HtmlNode nameNode = customNameTags[i];
                    string id = nameNode.GetAttributeValue("id", "");
                    string type = nameNode.GetAttributeValue("type", "");
                    string name = nameNode.GetAttributeValue("name", "");
                    string value = nameNode.GetAttributeValue("value", "");
                    System.Diagnostics.Trace.WriteLine("Id:" + id + "  type:" + type + "  name:" + name + "  value:" + value);
                    FormElement nameEl = new FormElement();
                    nameEl.Id = id;
                    nameEl.Type = type;
                    nameEl.Name = name;
                    nameEl.Value = value;

                    HtmlNode valueNode = customValueTags[i];
                    string vid = valueNode.GetAttributeValue("id", "");
                    string vtype = valueNode.GetAttributeValue("type", "");
                    string vname = valueNode.GetAttributeValue("name", "");
                    string vvalue = valueNode.GetAttributeValue("value", "");
                    System.Diagnostics.Trace.WriteLine("Id:" + vid + "  type:" + vtype + "  name:" + vname + "  value:" + vvalue);
                    FormElement valueEl = new FormElement();
                    valueEl.Id = vid;
                    valueEl.Type = vtype;
                    valueEl.Name = vname;
                    valueEl.Value = vvalue;
                    detail.CustomAttr.Add(nameEl, valueEl);
                }
            }

            nodeTags = htmlNode.SelectNodes(@".//input[@type='radio']");
            System.Diagnostics.Trace.WriteLine("radiobox===========================");

            if (nodeTags != null)
            {
                foreach (HtmlNode node in nodeTags)
                {
                    string id = node.GetAttributeValue("id", "");
                    string type = node.GetAttributeValue("type", "");
                    string name = node.GetAttributeValue("name", "");
                    string value = node.GetAttributeValue("value", "");
                    bool chk = node.Attributes["checked"] != null;
                    FormElement el = new FormElement();
                    el.Id = id;
                    el.Type = type;
                    el.Name = name;
                    el.Value = value;
                    el.Checked = chk;
                    System.Diagnostics.Trace.WriteLine("Id:" + id + "  type:" + type + "  name:" + name + "  checked:" + chk + "  value:" + value);
                    string propertyName = GetRadioBoxPropertyName(id, name, value);
                    PropertyInfo pInfo = typeOfClass.GetProperty(propertyName);
                    if (pInfo != null && pInfo.PropertyType.Name == "FormElement")
                    {
                        pInfo.SetValue(detail, el, null);
                    }
                }
            }
            System.Diagnostics.Trace.WriteLine("radiobox===========================");

            nodeTags = htmlNode.SelectNodes(@".//input[@type='checkbox']");
            if (nodeTags != null)
            {
                foreach (HtmlNode node in nodeTags)
                {
                    string id = node.GetAttributeValue("id", "");
                    string type = node.GetAttributeValue("type", "");
                    string name = node.GetAttributeValue("name", "");
                    string value = node.GetAttributeValue("value", "");
                    bool chk = node.Attributes["checked"] != null;
                    System.Diagnostics.Trace.WriteLine("Id:" + id + "  type:" + type + "  name:" + name + "  checked:" + chk + "  value:" + value);
                    FormElement el = new FormElement();
                    el.Id = id;
                    el.Type = type;
                    el.Name = name;
                    el.Value = value;
                    el.Checked = chk;
                    string propertyName = GetPropertyName(id, name);
                    PropertyInfo pInfo = typeOfClass.GetProperty(propertyName);
                    if (pInfo != null && pInfo.PropertyType.Name == "FormElement")
                    {
                        pInfo.SetValue(detail, el, null);
                    }
                }
            }

            System.Diagnostics.Trace.WriteLine("select===========================");
            nodeTags = htmlNode.SelectNodes(@".//select");
            if (nodeTags != null)
            {
                foreach (HtmlNode node in nodeTags)
                {
                    string id = node.GetAttributeValue("id", "");
                    string type = "select";
                    string name = node.GetAttributeValue("name", "");
                    string value = GetSelectValue(node);
                    System.Diagnostics.Trace.WriteLine("Id:" + id + "  type:" + type + "  name:" + name + "  value:" + value);
                    FormElement el = new FormElement();
                    el.Id = id;
                    el.Type = type;
                    el.Name = name;
                    el.Value = value;
                    string propertyName = GetPropertyName(id, name);
                    PropertyInfo pInfo = typeOfClass.GetProperty(propertyName);
                    if (pInfo != null && pInfo.PropertyType.Name == "FormElement")
                    {
                        pInfo.SetValue(detail, el, null);
                    }

                }
            }
            System.Diagnostics.Trace.WriteLine("select===========================");

            nodeTags = htmlNode.SelectNodes(@".//textarea");
            if (nodeTags != null)
            {
                foreach (HtmlNode node in nodeTags)
                {
                    string id = node.GetAttributeValue("id", "");
                    string type = node.GetAttributeValue("type", "");
                    string name = node.GetAttributeValue("name", "");
                    string value = node.InnerHtml;
                    System.Diagnostics.Trace.WriteLine("Id:" + id + "  type:" + type + "  name:" + name + "  value:" + value);
                    FormElement el = new FormElement();
                    el.Id = id;
                    el.Type = "textarea";
                    el.Name = name;
                    el.Value = value;
                    string propertyName = GetPropertyName(id, name);
                    PropertyInfo pInfo = typeOfClass.GetProperty(propertyName);
                    if (pInfo != null && pInfo.PropertyType.Name == "FormElement")
                    {
                        pInfo.SetValue(detail, el, null);
                    }
                }
            }
            return detail;
        }
Esempio n. 44
0
 public static FormContext GetValidationForForm(FormElement formElement) {
     return (FormContext)Type.GetField(formElement, _formValidationTag);
 }
 public void VisitFormElement(FormElement element)
 {
     element.Accept(this);
 }
Esempio n. 46
0
        private static DOMElement[] GetFormElementsWithName(FormElement formElement, string name) {
            ArrayList allElementsWithNameInForm = new ArrayList();

            DOMElementCollection allElementsWithName = Document.GetElementsByName(name);
            for (int i = 0; i < allElementsWithName.Length; i++) {
                DOMElement thisElement = allElementsWithName[i];
                if (IsElementInHierarchy(formElement, thisElement)) {
                    ArrayList.Add(allElementsWithNameInForm, thisElement);
                }
            }

            return (DOMElement[])allElementsWithNameInForm;
        }
        private static FormElement FormMap(IElement node)
        {
            if (node == null)
                return null;

            var el = new FormElement(value => node.SetAttribute("value", value))
            {
                Attributes = node.Attributes.ToDictionary(x => x.Name, y => y.Value),
                TagName = node.TagName,
                Text = node.TextContent,
                InnerHtml = node.InnerHtml,
                OuterHtml = node.OuterHtml
            };

            el.OnQuerySelector(query => Map(node.QuerySelector(query)));
            el.OnQuerySelectorAll(query => node.QuerySelectorAll(query).Select(Map));

            return el;
        }
 /// <summary>
 /// Detaches this instance from its associated object.
 /// </summary>
 public void Detach()
 {
     AssociatedObject = null;
 }
Esempio n. 49
0
 public static void HandleClick(FormElement form, DomEvent evt) {
     string additionalInput = MvcHelpers.SerializeSubmitButton(evt.Target, evt.OffsetX, evt.OffsetY);
     Type.SetField(form, "_additionalInput", additionalInput);
 }
Esempio n. 50
0
        public static void Main()
        {
            Document.Body.Style.Padding = "20px";

            var form = new FormElement
            {
                ClassName = "col-md-6"
            };

            var panel = Html5App.CreatePanel();
            form.AppendChild(panel);

            Document.Body.AppendChild(form);

            UpdateButton_Click(null);
        }
Esempio n. 51
0
 public Form()
 {
     _answers = new Dictionary<string, FormAnswer>();
     _elements = new Container(this);
 }
Esempio n. 52
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="form">HTML Form Element to send for keys/values. It will also encode file input content.</param>
 public FormData(FormElement form)
 {
 }
Esempio n. 53
0
 public Element(FormElement formElement)
     : base(formElement)
 {
 }
Esempio n. 54
0
		/// <summary>
		/// Writes the given form element to the given string builder.
		/// </summary>
		/// <param name="str">The string builder</param>
		/// <param name="element">The form element</param>
		private void WriteElement(StringBuilder str, FormElement element) {
			str.Append(String.Format("<label>{0}</label>", element.Label)) ;
			
			if (element.Type == FormElementType.Textbox || element.Type == FormElementType.Name || element.Type == FormElementType.Email) {
				str.Append(String.Format("<input name=\"{0}\" type=\"text\" {1} />", element.Label, element.IsRequired ? "class=\"required\"" : "")) ;
			} else if (element.Type == FormElementType.Textarea) {
				str.Append(String.Format("<textarea name=\"{0}\" {1}></textarea>", element.Label, element.IsRequired ? "class=\"required\"" : "")) ;
			}
		}
        public virtual ActionResult SaveElement(long formId, FormElementViewModel model)
        {
            FormsHelper.ValidateFormElement(model, ModelState);

            if (ModelState.IsValid)
            {
                FormsHelper.UpdateFormElement(model);

                var form = formsService.Find(formId);
                if (form == null || !permissionService.IsAllowed((Int32)FormOperations.Manage, this.CorePrincipal(), typeof(Form), form.Id, IsFormOwner(form), PermissionOperationLevel.Object))
                {
                    throw new HttpException((int)HttpStatusCode.NotFound, HttpContext.Translate("Messages.NotFound", ResourceHelper.GetControllerScope(this)));
                }

                var formElement = new FormElement();
                bool isEdited = model.Id > 0;
                if (isEdited)
                {
                    formElement = formsElementService.Find(model.Id);
                }
                else
                {
                    formElement.Form = form;
                    formElement.OrderNumber = formsElementService.GetLastOrderNumber(formElement.Form.Id);
                }

                if (formsElementService.Save(model.MapTo(formElement)))
                {
                    if (isEdited)
                    {
                        //save locale
                        var localeService = ServiceLocator.Current.GetInstance<IFormElementLocaleService>();
                        FormElementLocale locale = localeService.GetLocale(formElement.Id, model.SelectedCulture);
                        locale = model.MapLocaleTo(locale ?? new FormElementLocale { FormElement = formElement });
                        localeService.Save(locale);
                    }
                    Success(HttpContext.Translate("Messages.FormElementSaveSuccess", ResourceHelper.GetControllerScope(this))/*"Sucessfully save form element."*/);
                    return RedirectToAction(FormsMVC.Forms.ShowFormElements(formId));
                }
            }

            Error(HttpContext.Translate("Messages.ElementValidationError", ResourceHelper.GetControllerScope(this))/*"Validation errors occurred while processing this form. Please take a moment to review the form and correct any input errors before continuing."*/);
            return View("EditFormElement", model);
        }