예제 #1
0
        private async Task _toggleInlineEditClickHandler(bool enableEdit, bool applyChange)
        {
            //Show Edit
            if (enableEdit && !_editEnabled)
            {
                _editEnabled = true;
                await Task.Delay(5);

                new JsService(JSRuntime).FocusElementBySelector("#" + _inputElementId);
            }

            //Hide edit
            if (!enableEdit && _editEnabled)
            {
                var originalValue = FieldValueService.InitAsDecimal(Value);
                //Apply Change
                if (applyChange)
                {
                    if (_value != originalValue)
                    {
                        //Update Function should be called
                        await ValueChanged.InvokeAsync(new ChangeEventArgs { Value = _value });
                    }
                }
                //Abandon change
                else
                {
                    _value = originalValue;
                }
                _editEnabled = false;
            }
            await InvokeAsync(StateHasChanged);
        }
예제 #2
0
        protected override async Task OnParametersSetAsync()
        {
            if (JsonConvert.SerializeObject(_originalValue) != JsonConvert.SerializeObject(Value))
            {
                _originalValue = Value;
                _value         = FieldValueService.InitAsDecimal(Value);
            }

            _decimalPlaces = 0;
            if (Step.ToString(CultureInfo.InvariantCulture).IndexOf(".") > 0)
            {
                _decimalPlaces = Step.ToString(CultureInfo.InvariantCulture).Substring(Step.ToString(CultureInfo.InvariantCulture).IndexOf(".") + 1).Length;
            }

            await base.OnParametersSetAsync();
        }
        protected override async Task OnParametersSetAsync()
        {
            _cssList = new List <string>();

            if (!String.IsNullOrWhiteSpace(Class))
            {
                _cssList.Add(Class);
                if (!Class.Contains("form-control"))
                {                //Handle input-group case
                    _cssList.Add("form-control-plaintext");
                    if (Value == null)
                    {
                        _cssList.Add("form-control-plaintext--empty");
                    }
                }
            }
            else
            {
                _cssList.Add("form-control-plaintext");
                if (Value == null)
                {
                    _cssList.Add("form-control-plaintext--empty");
                }
            }

            var sizeSuffix = Size.ToDescriptionString();

            if (!String.IsNullOrWhiteSpace(sizeSuffix))
            {
                _cssList.Add($"form-control-{sizeSuffix}");
            }

            _value = null;
            if (Value != null)
            {
                _value = FieldValueService.InitAsDecimal(Value);
                _value = Math.Round(_value.Value, DecimalPlaces, MidpointRounding.AwayFromZero);
            }
            await base.OnParametersSetAsync();
        }
        protected override async Task OnParametersSetAsync()
        {
            _cssList = new List <string>();

            if (!String.IsNullOrWhiteSpace(Class))
            {
                _cssList.Add(Class);
            }

            var sizeSuffix = Size.ToDescriptionString();

            if (!String.IsNullOrWhiteSpace(sizeSuffix))
            {
                _cssList.Add($"form-control-{sizeSuffix}");
            }

            if (JsonConvert.SerializeObject(_originalValue) != JsonConvert.SerializeObject(Value))
            {
                _originalValue = Value;
                _value         = FieldValueService.InitAsDecimal(Value);
            }

            if (!String.IsNullOrWhiteSpace(Name))
            {
                AdditionalAttributes["name"] = Name;
            }

            if (!String.IsNullOrWhiteSpace(Placeholder))
            {
                AdditionalAttributes["placeholder"] = Placeholder;
            }

            if (!String.IsNullOrWhiteSpace(Title))
            {
                AdditionalAttributes["title"] = Title;
            }

            //Needs to be culture invariant as sometimes pure ToString results in "0,01" which is not the expected "0.01"
            if (Min != null)
            {
                AdditionalAttributes["min"] = Min?.ToString(CultureInfo.InvariantCulture);
            }

            if (Max != null)
            {
                AdditionalAttributes["max"] = Max?.ToString(CultureInfo.InvariantCulture);
            }

            AdditionalAttributes["step"] = Step.ToString(CultureInfo.InvariantCulture);

            _decimalPlaces = 0;
            if (Step.ToString(CultureInfo.InvariantCulture).IndexOf(".") > 0)
            {
                _decimalPlaces = Step.ToString(CultureInfo.InvariantCulture).Substring(Step.ToString(CultureInfo.InvariantCulture).IndexOf(".") + 1).Length;
            }

            if (_value != null)
            {
                _value = Math.Round(_value.Value, _decimalPlaces);
            }

            await base.OnParametersSetAsync();
        }