Example #1
0
        public TextEditRow(FormViewer formViewer, FormField field) : base(formViewer, field)
        {
            _header = new FormFieldHeader(field.Label);

            _editor = new FormEntry()
            {
                Text      = field.Value,
                IsEnabled = field.IsUserEditable,
            };

            if (Device.RuntimePlatform == Device.Android)
            {
                _editor.HeightRequest = 40;
            }


            _editor.IsPassword = field.FieldType == FieldTypes.Password.ToString();

            _editor.TextChanged += _editor_TextChanged;

            FieldTypes fieldType;

            if (Enum.TryParse <FieldTypes>(field.FieldType, out fieldType))
            {
                switch (FieldType)
                {
                case FieldTypes.Key:
                    _editor.Keyboard = Keyboard.Plain;
                    break;

                case FieldTypes.Decimal:
                case FieldTypes.Integer:
                    _editor.Keyboard = Keyboard.Numeric;
                    _editor.HorizontalTextAlignment = TextAlignment.End;
                    break;
                }

                _validationMessage = new FormFieldValidationMessage(field.RequiredMessage);

                Children.Add(_header);
                Children.Add(_editor);
                Children.Add(_validationMessage);
                Margin = RowMargin;
            }
        }
Example #2
0
        public SelectRow(FormViewer formViewer, FormField field) : base(formViewer, field)
        {
            _header            = new FormFieldHeader(field.Label);
            _validationMessage = new FormFieldValidationMessage(field.RequiredMessage);

            _picker = new Picker();

            if (field.Options != null)
            {
                var options = field.Options.Select(opt => opt.Label).ToList();
                if (!String.IsNullOrEmpty(field.Watermark))
                {
                    options.Insert(0, field.Watermark);
                }
                else
                {
                    options.Insert(0, "-select-");
                }

                _picker.IsEnabled     = field.IsEnabled;
                _picker.ItemsSource   = options;
                _picker.SelectedIndex = 0;
            }

            var selectedItem = field.Options.Where(opt => opt.Key == field.Value).FirstOrDefault();

            if (selectedItem != null)
            {
                var index = field.Options.IndexOf(selectedItem);
                _picker.SelectedIndex = index + 1;
            }
            else
            {
                _picker.SelectedIndex = 0;
            }

            Children.Add(_header);
            Children.Add(_picker);
            Children.Add(_validationMessage);

            _picker.SelectedIndexChanged += _picker_SelectedIndexChanged;
            Margin = RowMargin;
        }