Comments (11)
Also I think a lot of components work this way currently:
Yeah, almost all input components are broken right now and doing fundamentally wrong things like updating the Value
parameter and the ValueChanged
parameter. They should use ParameterState
and call the FieldChanged
method from the state change handler, which already handles the change logic. However, modifying input components is difficult because they are tightly coupled.
from mudblazor.
This does not currently seem possible.
Hi,
Why does it seem not possible if MudSwitch
supports two-way binding, which means you can intercept the state?
https://try.mudblazor.com/snippet/wEQokAvYgcmyfVZx
from mudblazor.
https://try.mudblazor.com/snippet/QOwSYqlbmDVZThXv
When using a MudForm and tracking FieldChanged, it does not honor the cancel.
from mudblazor.
Yeah, in v6 the FieldChanged
event is not consistent. It might fire when the field has not changed and might not fire when it has.
In v7, it's at least consistent after this change: #8693. It fires in both scenarios—whether changed or not—but the formFieldChangedEventArgs.NewValue
contains the correct value, and you can use this workaround:
<MudSwitch @ref="_mudSwitch" T="bool" Value="@Switch" ValueChanged="@OpenDialogAsync" />
private MudSwitch<bool> _mudSwitch = null!;
private async Task OnFormFieldChanged(FormFieldChangedEventArgs formFieldChangedEventArgs)
{
if (formFieldChangedEventArgs.Field is MudSwitch<bool> mudSwitch)
{
if (mudSwitch == _mudSwitch)
{
if (!EqualityComparer<bool>.Default.Equals((bool)formFieldChangedEventArgs.NewValue, Switch))
{
HasChanges = true;
}
}
}
await InvokeAsync(StateHasChanged);
}
I don't think there will be any fix for v6 unless you want to make a hotfix PR.
@igotinfected, do you know if it's still a bug in v7 that for the switch, the FieldChanged
event fires regardless of whether it was changed or not, or is this intended? I'm not much of a MudForm
user.
from mudblazor.
Don't think it's necessary to trigger the FieldChanged
event if the user decides to revert a value change. Currently we just don't handle that case. The change was already applied in the component, so form validation is called. In the meantime the user changes the value again (with the dialog in this case) but that is considered to be an extra change.
To handle this case we would have to not touch the Value
of a component if a ValueChanged
is provided and only do form validation after the component parameters are updated (with the parameter state framework for example). I tried messing around with the MudBooleanInput
implementation to see if I could get this to work, I got it working halfway but always end up with an infinite update loop :/ Need to try again with a fresh mind 🤪
Also I think a lot of components work this way currently:
from mudblazor.
@henon @igotinfected Also, what I noticed while doing this workaround #9158 (comment) is that the FieldId
is always different for the same instance whenever you access it.
It's because of this code:
MudBlazor/src/MudBlazor/Base/MudComponentBase.cs
Lines 79 to 81 in c15ea62
If the "id" attribute is not found, it will assign a random GUID, but this GUID will always be different because the property with =>
will be reevaluated.
Is this intended, or is it actually a bug and it should be something like this?
private readonly string _fieldId = Guid.NewGuid().ToString();
public string FieldId => UserAttributes.TryGetValue("id", out var id) && id != null
? id.ToString() ?? $"mudinput-{_fieldId}"
: $"mudinput-{_fieldId}";
from mudblazor.
If the "id" attribute is not found, it will assign a random GUID, but this GUID will always be different because the property with
=>
will be reevaluated.
Yeah looks like a bug, I think I did more or less the same logic for one of the input classes MudInput
or MudBaseInput
using the parameter state framework. That FieldId
is only used in two places too, I remember wanting to get rid of it eventually
from mudblazor.
yes it is a bug. the id should be cached
from mudblazor.
FYI working on a fix for MudBooleanInput
, got it working for MudSwitch
, just adding tests and checking for regressions, targetting v7+ though.
from mudblazor.
The MudCheckBox
component is causing me trouble in conjunction with the parameter state, will most likely request some help / thoughts on that in the next few days :p
from mudblazor.
The
MudCheckBox
component is causing me trouble in conjunction with the parameter state, will most likely request some help / thoughts on that in the next few days :p
Your struggles also could be related to missing this: #9225 as it breaks ParameterState
, or maybe something else. You can always ask me.
from mudblazor.
Related Issues (20)
- Use LanguageResource for MudDataGridPager HOT 3
- MudDatePicker and MudSelect not showing when clicked in .NET 8 blazor webassembly app HOT 2
- bugs with mudatepicker size and dialog titleformat HOT 2
- Tooltips disappearing immediately on mobile HOT 7
- MudTextField - Using ***InputType="InputType.Number"*** and ***MaxLength="6"*** does not prevent the entry of too many characters HOT 2
- MudExpansionPanel Expanded Not Updating HOT 2
- MudMessageBox Ignoring DialogOptions
- MudTreeView doesn't work after V7.0 migration HOT 1
- All the picker components should have an `OverflowBehavior` that is passed down to the underlying `MudPopover` HOT 1
- Href to static components HOT 8
- MudAutocomplete in a MudCard doesn't work in V7.1.1 HOT 3
- MudDataGrid ReadOnly=true SelectColumn is not readonly HOT 4
- False positive in MUD0002 Diagnostic when using @bind HOT 6
- Video Component HOT 1
- MudListItem SecondaryText not taking a disabled color when the item is disabled
- MudFileUpload not showing HOT 5
- MudFileUpload can not upload multiple times HOT 9
- EditForm or MudForm doen't work with Format currency HOT 5
- Tree view multi selection issue HOT 8
- Masked input slightly changes font-size
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mudblazor.