Example #1
0
        private void View_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            switch (e.PropertyName)
            {
            case nameof(Label):
                this.Label = AtomForm.GetLabel(Content);
                UpdateCell();
                break;

            case nameof(LabelColor):
                this.LabelColor = AtomForm.GetLabelColor(Content);
                UpdateCell();
                break;

            case nameof(Error):
                this.Error = AtomForm.GetError(Content);
                UpdateCell();
                break;

            case nameof(Description):
                this.Description = AtomForm.GetDescription(Content);
                UpdateCell();
                break;

            case nameof(IsRequired):
                this.IsRequired = AtomForm.GetIsRequired(Content);
                UpdateCell();
                break;

            case nameof(Content):
                UpdateCell();
                break;
            }
        }
Example #2
0
 internal IEnumerable AllFields(bool flat = false)
 {
     System.Diagnostics.Debug.WriteLine("Enumerating Form Fields");
     // var list = new ArrayList();
     if (flat)
     {
         foreach (var item in Groups)
         {
             // list.Add(item);
             yield return(item);
         }
     }
     else
     {
         foreach (object item in Groups.GroupBy(x => AtomForm.GetCategory(x)))
         {
             // list.Add(item);
             yield return(item);
         }
     }
     //foreach (var item in list)
     //{
     //    System.Diagnostics.Debug.WriteLine(item.GetType().FullName);
     //}
     // return list;
 }
Example #3
0
        protected override void SetDefaultValidator()
        {
            AtomForm.SetValidator(this, DefaultValidator);

            this.IsPassword = true;

            this.MinimumLength = 5;
            this.MaximumLength = 16;
        }
Example #4
0
        internal Task OnSubmitCommand()
        {
            AtomForm form = this.GetParentOfType <AtomForm>();

            var af = form?.ValidateCommand;

            af?.Execute(this.CommandParameter);
            return(Task.CompletedTask);
        }
        public override UITableViewCell GetCell(Cell item, UITableViewCell reusableCell, UITableView tv)
        {
            var r = base.GetCell(item, reusableCell, tv);


            var viewCell = (ViewCell)item;

            var content = viewCell?.BindingContext as Xamarin.Forms.View;

            if (content != null && !(content is Editor))
            {
                var textField = Platform.GetRenderer(content)?.NativeView?.GetPropertyValue("Control") as UITextField;
                if (textField != null)
                {
                    var next = AtomForm.GetFocusNext(content);

                    var submitButton = next as AtomSubmitButton;

                    textField.ReturnKeyType = submitButton != null ? UIReturnKeyType.Go : UIReturnKeyType.Next;


                    textField.ShouldReturn = (tf) => {
                        var nextField = Platform.GetRenderer(next)?.NativeView?.GetPropertyValue("Control") as UIView;
                        if (nextField == null)
                        {
                            tf.ResignFirstResponder();
                            return(false);
                        }

                        var cell = nextField.FindParent <UITableViewCell>();

                        cell?.BecomeFirstResponder();

                        //var button = nextField as UIButton;
                        if (submitButton != null)
                        {
                            tf.ResignFirstResponder();
                            //button.SendActionForControlEvents(UIControlEvent.TouchUpInside);
                            submitButton.OnSubmitCommand();
                            return(false);
                        }

                        var txt = nextField as UITextField;
                        if (txt != null)
                        {
                            tf.ResignFirstResponder();
                            txt.BecomeFirstResponder();
                        }

                        return(false);
                    };
                }
            }

            return(r);
        }
Example #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="item"></param>
        /// <param name="convertView"></param>
        /// <param name="parent"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        protected override Android.Views.View GetCellCore(Cell item, Android.Views.View convertView, ViewGroup parent, Context context)
        {
            var r = base.GetCellCore(item, convertView, parent, context);



            var viewCell = (ViewCell)item;

            var content = viewCell.BindingContext as Xamarin.Forms.View;

            if (content != null && !(content is Editor))
            {
                var textField = Platform.GetRenderer(content)?.GetPropertyValue("Control") as EditText;
                if (textField != null)
                {
                    var next = AtomForm.GetFocusNext(content);


                    textField.ImeOptions = next is AtomSubmitButton ? ImeAction.Go : ImeAction.Next;

                    textField.EditorAction += (s, e) => {
                        if (e.ActionId == ImeAction.Next
                            ||
                            e.ActionId == ImeAction.Go)
                        {
                            var nextField = Platform.GetRenderer(next)?.GetPropertyValue("Control") as Android.Views.View;

                            var button = nextField as Android.Widget.Button;
                            if (button != null)
                            {
                                button.CallOnClick();

                                // hide keyboard...

                                HideKeyboard(textField);

                                return;
                            }

                            var tf = nextField as EditText;
                            if (tf != null)
                            {
                                tf.RequestFocus();
                                return;
                            }

                            HideKeyboard(textField);
                        }
                    };
                }
            }



            return(r);
        }
Example #7
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="view"></param>
 public void BindView(View view)
 {
     this.Content          = view;
     view.PropertyChanged += View_PropertyChanged;
     Label            = AtomForm.GetLabel(view);
     this.LabelColor  = AtomForm.GetLabelColor(view);
     this.Error       = AtomForm.GetError(view);
     this.Description = AtomForm.GetDescription(view);
     this.IsRequired  = AtomForm.GetIsRequired(view);
     this.UpdateCell();
 }
        public static IDisposable BindKeyboardActions(Xamarin.Forms.View content)
        {
            if (content != null && !(content is Editor))
            {
                var textField = Platform.GetRenderer(content)?.NativeView?.GetPropertyValue("Control") as UITextField;
                if (textField != null)
                {
                    var next = AtomForm.GetFocusNext(content);

                    var submitButton = next as AtomSubmitButton;

                    textField.ReturnKeyType = submitButton != null ? UIReturnKeyType.Go : UIReturnKeyType.Next;


                    textField.ShouldReturn = (tf) => {
                        var nextField = Platform.GetRenderer(next)?.NativeView?.GetPropertyValue("Control") as UIView;
                        if (nextField == null)
                        {
                            tf.ResignFirstResponder();
                            return(false);
                        }

                        var cell = nextField.FindParent <UITableViewCell>();

                        cell?.BecomeFirstResponder();

                        //var button = nextField as UIButton;
                        if (submitButton != null)
                        {
                            tf.ResignFirstResponder();
                            //button.SendActionForControlEvents(UIControlEvent.TouchUpInside);
                            submitButton.OnSubmitCommand();
                            return(false);
                        }

                        var txt = nextField as UITextField;
                        if (txt != null)
                        {
                            tf.ResignFirstResponder();
                            txt.BecomeFirstResponder();
                        }

                        return(false);
                    };

                    new AtomDisposableAction(() => {
                        textField.ShouldReturn = null;
                    });
                }
            }

            return(new AtomDisposableAction());
        }
Example #9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="item"></param>
        /// <param name="convertView"></param>
        /// <param name="parent"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public static IDisposable BindKeyboardActions(Xamarin.Forms.View content)
        {
            if (content != null && !(content is Editor))
            {
                var textField = Platform.GetRenderer(content)?.GetPropertyValue("Control") as EditText;
                if (textField != null)
                {
                    var next = AtomForm.GetFocusNext(content);


                    textField.ImeOptions = next is AtomSubmitButton ? ImeAction.Go : ImeAction.Next;

                    EventHandler <EditorActionEventArgs> editorAction = (s, e) => {
                        if (e.ActionId == ImeAction.Next
                            ||
                            e.ActionId == ImeAction.Go)
                        {
                            var nextField = Platform.GetRenderer(next)?.GetPropertyValue("Control") as Android.Views.View;

                            var button = nextField as Android.Widget.Button;
                            if (button != null)
                            {
                                button.CallOnClick();

                                // hide keyboard...

                                HideKeyboard(textField);

                                return;
                            }

                            var tf = nextField as EditText;
                            if (tf != null)
                            {
                                tf.RequestFocus();
                                return;
                            }

                            HideKeyboard(textField);
                        }
                    };

                    textField.EditorAction += editorAction;

                    return(new AtomDisposableAction(() => {
                        textField.EditorAction -= editorAction;
                    }));
                }
            }

            return(new AtomDisposableAction(() => {
            }));
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="propertyName"></param>
 protected override void OnPropertyChanged([CallerMemberName] string propertyName = null)
 {
     base.OnPropertyChanged(propertyName);
     if (propertyName == "IsFocused")
     {
         if (!this.IsFocused)
         {
             // we just lost the focus??
             // lets validate this textbox...
             if (AtomForm.GetError(this) != null)
             {
                 AtomValidationRule.Validate(this);
             }
         }
     }
 }
        /// <summary>
        ///
        /// </summary>
        public AtomComboBox()
        {
            AtomForm.SetValidator(this, DefaultValidator);

            this.GestureRecognizers.Add(new TapGestureRecognizer
            {
                Command = new AtomCommand(async() => await OnContentTappedCommand())
            });

            this.ItemTemplate = new DataTemplate(typeof(AtomLabelTemplate));

            this.Padding      = new Thickness(5);
            this.OutlineColor = Color.Accent;

            OnSelectedItemChanged(null, null);
        }
Example #12
0
        /// <summary>
        ///
        /// </summary>
        public AtomDatePicker()
        {
            AtomForm.SetValidator(this, DefaultValidator);

            contentLabel = new Label {
            };
            contentLabel.VerticalTextAlignment = TextAlignment.Center;
            contentLabel.GestureRecognizers.Add(new TapGestureRecognizer {
                Command = new AtomCommand(async() => await OnTapCommandAsync())
            });

            Content = contentLabel;

            this.ControlTemplate = new ControlTemplate(typeof(AtomDatePickerTemplate));

            contentLabel.Text = EmptyLabel;
        }
 internal IEnumerable AllFields(bool flat = false)
 {
     System.Diagnostics.Debug.WriteLine("Enumerating Form Fields");
     if (flat)
     {
         foreach (var item in Groups)
         {
             yield return(item);
         }
     }
     else
     {
         foreach (object item in Groups.GroupBy(x => AtomForm.GetCategory(x)))
         {
             yield return(item);
         }
     }
 }
        private static void OnValidatorChanged(BindableObject bindable, object oldValue, object newValue)
        {
            AtomPropertyValidator v = newValue as AtomPropertyValidator;

            if (v == null)
            {
                return;
            }
            bindable.PropertyChanged += (s, e) => {
                var error = AtomForm.GetError(bindable);
                if (string.IsNullOrWhiteSpace(error))
                {
                    return;
                }
                if (e.PropertyName == v.BindableProperty?.PropertyName || e.PropertyName == v.Property)
                {
                    AtomValidationRule.Validate(bindable as View);
                }
            };
        }
Example #15
0
        public AtomFormItemsControl(AtomForm form)
        {
            this.Form          = form;
            layout             = new StackLayout();
            this.Content       = layout;
            layout.Orientation = StackOrientation.Vertical;

            var dt = new DataTemplate(() =>
            {
                // Grid grid = new Grid();
                var afg = Form.FieldStyle.CreateContent() as AtomFieldGrid;
                if (afg == null)
                {
                    throw new InvalidOperationException("FieldStyle must contain root element of type AtomFieldGrid");
                }
                afg.Form = this.Form;
                return(afg);
            });

            BindableLayout.SetItemTemplate(layout, dt);

            layout.Spacing = 5;
        }
Example #16
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="view"></param>
 public void BindView(View view)
 {
     this.Content = view;
     if (view == null)
     {
         return;
     }
     view.SetBinding(BindingContextProperty, new Binding
     {
         Path   = "BindingContext",
         Source = this.Form
     });
     view.PropertyChanged += View_PropertyChanged;
     Label            = AtomForm.GetLabel(view);
     this.LabelColor  = AtomForm.GetLabelColor(view);
     this.Error       = AtomForm.GetError(view);
     this.Description = AtomForm.GetDescription(view);
     this.IsRequired  = AtomForm.GetIsRequired(view);
     this.SetBinding(IsVisibleProperty, new Binding {
         Path = "IsVisible", Source = view
     });
     this.lastDisposable.SetTarget(AtomFieldRenderer.BindKeyboardActions(view));
     this.UpdateCell();
 }
 protected override void SetDefaultValidator()
 {
     AtomForm.SetValidator(this, DefaultValidator);
 }
 public FieldCollection(AtomForm form)
 {
     this.Form = form;
 }
 protected virtual void SetDefaultValidator()
 {
     AtomForm.SetValidator(this, DefaultValidator);
 }