Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear Signature Programmatically #26

Open
mouse0270 opened this issue Apr 3, 2024 · 3 comments
Open

Clear Signature Programmatically #26

mouse0270 opened this issue Apr 3, 2024 · 3 comments
Assignees
Labels
bug Something isn't working Needs: Author Feeback The author of this issue needs to respond in order for us to continue investigating this issue.

Comments

@mouse0270
Copy link

I am using MudBlazor Dialog to show the SignaturePad and this appears to work as expected. The Dialog is showing up and I can use the Signature pad. The problem becomes when I want to clear it. I set ShowClearButton to false and then added a dialog button for clear, so the UI will flow as expected. However, when the user hits the clear button, the SignaturePad keeps the data.

@using MudBlazor
@using SignaturePad

<MudDialog>
    <DialogContent>
		<SignaturePad @bind-Value="bSignature" ShowClearButton="false" style="max-width: calc(100vw - 3rem); width: 800px" />
    </DialogContent>
	<DialogActions>
        <MudButton OnClick="Clear">Clear</MudButton>
        <MudSpacer />
        <MudButton OnClick="Cancel">Cancel</MudButton>
        <MudButton Color="Color.Error" OnClick="Submit">Sign Document</MudButton>
    </DialogActions>
</MudDialog>

@code {
    [CascadingParameter] MudDialogInstance MudDialog { get; set; }
	public byte[] bSignature { get; set; } = Array.Empty<byte>();
	public string SignatureAsBase64 => System.Text.Encoding.UTF8.GetString(bSignature);

	protected override void OnInitialized() {
		
	}

    void Submit() => MudDialog.Close(DialogResult.Ok(true));
    void Cancel() => MudDialog.Cancel();
    private async Task Clear() {
        bSignature = Array.Empty<byte>();
        Console.WriteLine($"Signature cleared {bSignature.Length}");

        StateHasChanged();
    }
}

I can see that the console outputs a length of 0 after setting the array to Array.Empty<byte>() but the SignaturePad does not appear to update to show this.

#12 is where I got the idea to clear set the Byte to an empty array to clear the signature pad, also I am using version 8.0.0

@MarvinKlein1508 MarvinKlein1508 added the bug Something isn't working label Apr 3, 2024
@MarvinKlein1508 MarvinKlein1508 self-assigned this Apr 3, 2024
@MarvinKlein1508
Copy link
Owner

Hi! Thanks for contacting me. I will try and take a look on this by tomorrow.

It would help me a lot if you could provide a small example repository as I'm not this familiar with MudBlazor.

Thanks!
-Marvin

@MarvinKlein1508
Copy link
Owner

MarvinKlein1508 commented Apr 4, 2024

Good morning!

Please try this one out:

@using MudBlazor
@using SignaturePad

<MudDialog>
    <DialogContent>
		<SignaturePad @ref="_signaturePad" @bind-Value="bSignature" ShowClearButton="false" style="max-width: calc(100vw - 3rem); width: 800px" />
    </DialogContent>
	<DialogActions>
        <MudButton OnClick="Clear">Clear</MudButton>
        <MudSpacer />
        <MudButton OnClick="Cancel">Cancel</MudButton>
        <MudButton Color="Color.Error" OnClick="Submit">Sign Document</MudButton>
    </DialogActions>
</MudDialog>

@code {
    [CascadingParameter] MudDialogInstance MudDialog { get; set; }
	public byte[] bSignature { get; set; } = Array.Empty<byte>();
	public string SignatureAsBase64 => System.Text.Encoding.UTF8.GetString(bSignature);

    private SignaturePad _signaturePad = default!;

	protected override void OnInitialized() {
		
	}

    void Submit() => MudDialog.Close(DialogResult.Ok(true));
    void Cancel() => MudDialog.Cancel();
    private async Task Clear() {
        await _signaturePad.Clear();
        Console.WriteLine($"Signature cleared {bSignature.Length}");

        StateHasChanged();
    }
}

@MarvinKlein1508 MarvinKlein1508 added the Needs: Author Feeback The author of this issue needs to respond in order for us to continue investigating this issue. label Apr 9, 2024
@dngrozdanov
Copy link

dngrozdanov commented May 13, 2024

Hi @mouse0270, you can also try to re-render the dialog after clean, there is a method in MudDialogInstance, to force re-render of the component.
StateHasChanged is not working properly with MudDialogs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Needs: Author Feeback The author of this issue needs to respond in order for us to continue investigating this issue.
Projects
None yet
Development

No branches or pull requests

3 participants