예제 #1
0
        /// <inheritdoc/>
        public override async Task SetParametersAsync(ParameterView parameters)
        {
            var colorChanged                  = parameters.TryGetValue <string>(nameof(Color), out var color) && !Color.IsEqual(color);
            var paletteChanged                = parameters.TryGetValue(nameof(Palette), out string[] palette) && !Palette.AreEqual(palette);
            var showPaletteChanged            = parameters.TryGetValue(nameof(ShowPalette), out bool showPalette) && ShowPalette != showPalette;
            var hideAfterPaletteSelectChanged = parameters.TryGetValue(nameof(HideAfterPaletteSelect), out bool hideAfterPaletteSelect) && HideAfterPaletteSelect != hideAfterPaletteSelect;
            var disabledChanged               = parameters.TryGetValue(nameof(Disabled), out bool disabled) && Disabled != disabled;
            var readOnlyChanged               = parameters.TryGetValue(nameof(ReadOnly), out bool readOnly) && ReadOnly != readOnly;

            if (colorChanged)
            {
                await CurrentValueHandler(color);

                if (Rendered)
                {
                    ExecuteAfterRender(async() => await JSModule.UpdateValue(ElementRef, ElementId, color));
                }
            }

            if (Rendered && (paletteChanged ||
                             showPaletteChanged ||
                             hideAfterPaletteSelectChanged ||
                             disabledChanged ||
                             readOnlyChanged))
            {
                ExecuteAfterRender(async() => await JSModule.UpdateOptions(ElementRef, ElementId, new
                {
                    Palette                = new { Changed = paletteChanged, Value = palette },
                    ShowPalette            = new { Changed = showPaletteChanged, Value = showPalette },
                    HideAfterPaletteSelect = new { Changed = hideAfterPaletteSelectChanged, Value = hideAfterPaletteSelect },
                    Disabled               = new { Changed = disabledChanged, Value = disabled },
                    ReadOnly               = new { Changed = readOnlyChanged, Value = readOnly },
                }));
            }

            await base.SetParametersAsync(parameters);

            if (ParentValidation != null)
            {
                if (parameters.TryGetValue <Expression <Func <string> > >(nameof(ColorExpression), out var expression))
                {
                    await ParentValidation.InitializeInputExpression(expression);
                }

                await InitializeValidation();
            }
        }