Ejemplo n.º 1
0
        public void VerifyString_Input()
        {
            var maskedTextProvider = new MaskedTextProvider(TestComplexDigitMask, new CultureInfo("en-US"));

            Assert.True(maskedTextProvider.VerifyString("10000000"));
            Assert.False(maskedTextProvider.VerifyString("A"));
        }
Ejemplo n.º 2
0
        public void VerifyString_Input_TestPosition_ResultHint()
        {
            var maskedTextProvider = new MaskedTextProvider(TestComplexDigitMask, new CultureInfo("en-US"));

            Assert.True(maskedTextProvider.VerifyString("10000000", out int testPosition, out MaskedTextResultHint resultHint));
            Assert.Equal(10, testPosition);
            Assert.Equal(MaskedTextResultHint.Success, resultHint);

            Assert.False(maskedTextProvider.VerifyString("A", out testPosition, out resultHint));
            Assert.Equal(1, testPosition);
            Assert.Equal(MaskedTextResultHint.DigitExpected, resultHint);
        }
Ejemplo n.º 3
0
        protected override void OnPreviewTextInput(TextCompositionEventArgs e)
        {
            System.ComponentModel.MaskedTextResultHint hint;
            int TestPosition;

            if (e.Text.Length == 1)
            {
                this._NewTextIsOk = _mprovider.VerifyChar(e.Text[0], this.CaretIndex, out hint);
            }
            else
            {
                this._NewTextIsOk = _mprovider.VerifyString(e.Text, out TestPosition, out hint);
            }

            base.OnPreviewTextInput(e);
        }
        /// <summary>
        /// Check if the received string value matches with the Introduction Mask for Time datatype.
        /// </summary>
        /// <param name="stringValue">String to be checked.</param>
        /// <returns>Returns true if the received string matches with Introduction Mask.</returns>
        private bool IsValidTimeAccordingMask(string stringValue)
        {
            bool result = true;

            if (Mask != string.Empty)
            {
                MaskedTextProvider maskTextProvider = new MaskedTextProvider(ConvertMask2DisplayMask(Mask));
                result = maskTextProvider.VerifyString(stringValue);
            }
            return(result);
        }
        /// <summary>
        /// Check if the received string value matches with the Introduction Mask for String datatype.
        /// </summary>
        /// <param name="stringValue">String to be checked.</param>
        /// <returns>Returns true if the received string matches with Introduction Mask.</returns>
        private bool IsValidStringAccordingMask(string stringValue)
        {
            bool result = true;

            if (Mask != string.Empty)
            {
                MaskedTextProvider maskTextProvider = new MaskedTextProvider(Mask);
                maskTextProvider.IncludeLiterals = false;
                maskTextProvider.Set(stringValue);
                result = maskTextProvider.VerifyString(stringValue) && maskTextProvider.MaskCompleted;
            }
            return(result);
        }
        /// <summary>
        /// Checks if the editor has value or not.
        /// </summary>
        /// <returns>Return true if the editor has a value.</returns>
        private bool HasValue()
        {
            bool lResult = true;

            if (Mask != null && !Mask.Equals(string.Empty))
            {
                // Only String and Time data types can have masks in this Presentation. Check them separately.
                if (mDataType == ModelType.Time)
                {
                    // Get the Time value without Time separators in order to check if the editor control has value.
                    string lAuxStringValue = mMaskedTextBoxIT.Text.Replace(mMaskedTextBoxIT.Culture.DateTimeFormat.TimeSeparator, "");
                    lResult = !string.IsNullOrEmpty(lAuxStringValue.Trim());
                }
                else
                {
                    // String data type.
                    MaskedTextProvider maskTextProvider = new MaskedTextProvider(Mask);
                    maskTextProvider.IncludeLiterals = false;
                    if (!maskTextProvider.VerifyString(mMaskedTextBoxIT.Text))
                    {
                        // If the value assigned to the control does not satisfies the mask,
                        // check if the editor control Text has value.
                        lResult = (mMaskedTextBoxIT.Text != string.Empty);
                    }
                    else
                    {
                        // If the value assigned satisfies the mask
                        // (it is not mandatory that the mask has been completed),
                        // assign the value to the MaskTextProvider and then check if
                        // it has value.
                        maskTextProvider.Set(mMaskedTextBoxIT.Text);
                        string auxString = maskTextProvider.ToString(false, false);
                        lResult = !string.IsNullOrEmpty(auxString);
                    }
                }
            }
            else
            {
                lResult = !mMaskedTextBoxIT.Text.Equals(string.Empty);
            }
            return(lResult);
        }
Ejemplo n.º 7
0
        private async Task OnValueChange(ChangeEventArgs e)
        {
            var inputValue = e.Value?.ToString();

            if (!string.IsNullOrEmpty(Mask) && !string.IsNullOrEmpty(inputValue))
            {
                var provider = new MaskedTextProvider(Mask);

                _showMaskDescription = false;

                if (inputValue.Length != Mask.Length)
                {
                    _showMaskDescription = true;
                    DropInputValue();
                }
                else
                {
                    var checkResult = provider.VerifyString(inputValue, out var position, out var hint);

                    if (!checkResult)
                    {
                        _showMaskDescription = true;
                        DropInputValue();
                    }
                    else
                    {
                        _showMaskDescription = false;
                        _value = inputValue;
                    }
                }

                this.StateHasChanged();
            }
            else
            {
                _value = inputValue;
            }

            await ValueChanged.InvokeAsync(_value);

            await Changed.InvokeAsync(_value);
        }