Example #1
0
        private static void ParseMetaData(XElement xml, DynamicFormDefinition definition)
        {
            var metaData = xml.Element("MetaData");

            if (metaData == null)
            {
                return;
            }

            var forceHttpsConnectionElement = metaData.Element("forceHttpsConnection");

            if (forceHttpsConnectionElement != null)
            {
                definition.Model.Attributes.Add(new ForceHttpsConnectionAttribute());
            }

            var requiresCaptchaElement = metaData.Element("requiresCaptcha");

            if (requiresCaptchaElement != null)
            {
                definition.Model.Attributes.Add(new RequiresCaptchaAttribute());
            }

            ParseMetaDataDefaultValues(metaData, definition);
            ParseSubmitHandlers(metaData, definition);
            ParseFormSettings(metaData, definition);
        }
Example #2
0
        private static void ParseMetaDataDefaultValues(XElement metaData, DynamicFormDefinition definition)
        {
            var defaultValuesElement = metaData.Element("DefaultValues");

            if (defaultValuesElement != null)
            {
                foreach (var handler in defaultValuesElement.Elements("Add"))
                {
                    var fieldName      = handler.Attribute("field").Value;
                    var functionMarkup = XElement.Parse(handler.Attribute("functionMarkup").Value);

                    definition.DefaultValues.Add(fieldName, functionMarkup);
                }
            }
        }
Example #3
0
        public override IDynamicDefinition Load(string name, XElement xml)
        {
            var model = new FormModel(name)
            {
                SetDefaultValuesHandler = DynamicFormsFacade.SetDefaultValues
            };

            var fields = xml.Element("Fields").Elements("Add");

            foreach (var f in fields)
            {
                var attrs     = new List <Attribute>();
                var fieldName = f.Attribute("name").Value;

                foreach (var el in f.Elements())
                {
                    switch (el.Name.LocalName)
                    {
                    case "InputElement": ParseInputElement(el, attrs); break;

                    case "ValidationRules": ParseValidationRules(el, attrs); break;

                    case "DataSource": ParseDataSource(el, attrs); break;

                    case "Dependencies": ParseDependencies(el, attrs); break;
                    }
                }

                var valueTypeAttr = f.Attribute("valueType");
                var valueType     = valueTypeAttr != null?Type.GetType(valueTypeAttr.Value) : typeof(string);

                var formField = new FormFieldModel(model, fieldName, valueType, attrs);

                var label = Localization.EvaluateT(formField, "Label", null);
                if (label == null)
                {
                    formField.Attributes.Add(new HiddenFieldAttribute());
                }
                else
                {
                    formField.Attributes.Add(new FieldLabelAttribute());
                }

                var placeholderText = Localization.EvaluateT(formField, "PlaceholderText", null);
                if (placeholderText != null)
                {
                    formField.Attributes.Add(new PlaceholderTextAttribute());
                }

                var help = Localization.EvaluateT(formField, "Help", null);
                if (help != null)
                {
                    formField.Attributes.Add(new FieldHelpAttribute());
                }

                var isReadOnlyAttr = f.Attribute("isReadOnly");
                if (isReadOnlyAttr != null)
                {
                    formField.IsReadOnly = bool.Parse(isReadOnlyAttr.Value);
                }

                var formatAttribute = f.Attribute("format");
                if (formatAttribute != null)
                {
                    formField.Attributes.Add(new DisplayFormatAttribute(formatAttribute.Value));
                }

                if (valueTypeAttr == null)
                {
                    formField.EnsureValueType();
                }

                model.Fields.Add(formField);
            }

            var definition = new DynamicFormDefinition(model);

            ParseMetaData(xml, definition);

            return(definition);
        }