A Razor class library for interacting with SweetAlert2
If you need to support these old browsers in your project, please use the previous major release v4.5.0
.QueueAsync()
, .GetQueueStepAsync()
, .InsertQueueStepAsync()
, .DeleteQueueStepAsync()
methods are REMOVEDasync/await
can perfectly replace all use-cases of .QueueAsync()
.
sweetalert2@11
introduced a variety of styling changes.
Examples and explainations for these changes can be found on the sweetalert2 v11.0.0 release notes.
You can now specify global defaults during Startup for your SweetAlertOptions that apply to all your SweetAlert2 dialogs.
services.AddSweetAlert2(options => {
options.DefaultOptions = new SweetAlertOptions {
HeightAuto = false
};
});
View the README.md for more information
sweetalert2
to 11.0.17
@sweetalert2/themes
to 5.0.0
Blazor dependencies are now dependant on which version of .NET is being used in the application.
Microsoft.AspNetCore.Components
(>= 3.1.0
&& < 5.0.0
)Microsoft.AspNetCore.Components.Web
(>= 3.1.0
&& < 5.0.0
)Microsoft.AspNetCore.Components
(>= 3.1.0
&& < 5.0.0
)Microsoft.AspNetCore.Components.Web
(>= 3.1.0
&& < 5.0.0
)Microsoft.AspNetCore.Components
(>= 5.0.0
&& < 6.0.0
)Microsoft.AspNetCore.Components.Web
(>= 5.0.0
&& < 6.0.0
)Previously, if a user were to change their default JSON serialization settings, it would break the JSInterop. Now interop properties won't be affected by user serialization settings.
Generally, as a rule, this library doesn't include deprecated methods from the sweetalert2
library.
The library just deprecated all of the queue functions in anticiaption of v11
which will remove them.
If I were to remove them, that would require a new major verison release now, and then another when they realease v11
.
So for now those methods are also deprecated in this library.
QueueAsync
GetQueueStepAsync
InsertQueueStepAsync
DeleteQueueStepAsync
sweetalert2
to 10.16.7
@sweetalert2/themes
to 4.0.5
SweetAlertOptions
propertiesReturnFocus
ShowLoaderOnDeny
CustomClass.InputLabel
CustomClass.HtmlContainer
sweetalert2
to 10.16.0
@sweetalert2/themes
to 4.0.3
Microsoft.AspNetCore.Components
to 3.1.14
Microsoft.AspNetCore.Components.Web
to 3.1.14
Microsoft.CodeAnalysis.FxCopAnalyzers
with Microsoft.CodeAnalysis.NetAnalyzers
version 5.0.3
sweetalert2
to 10.10.1
Microsoft.AspNetCore.Components
to 3.1.10
Microsoft.AspNetCore.Components.Web
to 3.1.10
Microsoft.AspNetCore.Components
version 5.0.0
is now out. It only supports .NET 5, not .NET Standard 2.0. Upgrading would make this library only usable by .NET 5 applications. I will not be upgrading to >= 5.0.0
unless there are new features added to the Blazor framework worth taking advantage of. In that case, the library would start targeting multiple frameworks in order to preserve functionality on pre .NET 5 applications.
Previously, the Swal
JavaScript object was used by JSInterop but not available through window.Swal
. That meant that you couldn't write your own JavaScript snippets that reference Swal
without duplicating the library through a CDN tag.
Now, if you add the <script src="_content/CurrieTechnologies.Razor.SweetAlert2/sweetAlert2.min.js"></script>
tag to your page, that page has access to Swal
and you can do custom functionality like assigning event listeners, and in this issue: (https://github.com/Basaingeal/Razor.SweetAlert2/issues/1012)
Previously, this was not possible due to Swal
not being available on the DOM. It will now work.
<script src="_content/CurrieTechnologies.Razor.SweetAlert2/sweetAlert2.min.js"></script>
<script>
function bindSwalMouseOver() {
var toast = Swal.getContainer();
toast.removeEventListener('mouseover', Swal.stopTimer);
toast.removeEventListener('mouseleave', Swal.resumeTimer);
toast.addEventListener('mouseenter', Swal.stopTimer);
toast.addEventListener('mouseleave', Swal.resumeTimer);
}
</script>
PreDeny
Callback propoertyThere is a new property on SweetAlertOptions
called PreDeny
. This is fired when someone hits the deny button. It can be a sync or async function that takes a string and returns a string (Func<string, Task<string>>
or Func<string, string>
).
The input string of the callback is the value that would be returned by SweetAlertResult.Value
.
If you return null
, the original value is passed along to SweetAlertResult.Value
.
If you return "false"
, the popup does not close.
If you return anything else, that returned value goes in to SweetAlertResult.Value
.
NB: Be sure that ReturnInputValueOnDeny
is set to true in order for the value to be passed into the PreDeny
callback function.
var result = await Swal.FireAsync(new SweetAlertOptions
{
Input = SweetAlertInputType.Select,
InputOptions = new Dictionary<string, string>
{
{ "DC", "Don't Close" },
{ "Normal Result", "Result is Normal" },
{ "OV", "Result is overriden" }
},
ReturnInputValueOnDeny = true,
PreDeny = new PreDenyCallback((string input) =>
{
return input switch
{
"DC" => "false",
"OV" => "PreConfirm override!!!!",
_ => null
};
}, this),
ShowDenyButton = true
});
// If "Don't Close" is selected, modal doesn't close.
// If "Result is Normal" is selected, result.Value = "Normal Result"
// If "Result is overriden" is selected, result.Value = "PreConfirm override!!!!"
PreConfirm
callback propertyThe PreConfirm
callback has been in place form day one.
If you returned null
, the original value would be returned to SweetAlertResult.Value
, otherwise the returned value of the callback would be passed to SweetAlertResult.Value
.
Now, if you return "false"
, the popup modal will stay open.
sweetalert2
to 10.9.0
@sweetalert2/themes
to 4.0.1
Just a couple of releases after sweetalert2@10
was released, they renamed the lifecycle hooks and deprecated the old names. (https://github.com/sweetalert2/sweetalert2/pull/2057)
As a rule, this wrapper library does not include deprecated functionality.
As a result, the old lifecycle hook names have been completely replaced with the new ones, resulting in a new major version.
Hooks were previously named as follows:
Before Hook | After hook |
---|---|
OnBeforeOpen |
OnOpen |
OnRender |
|
OnClose |
OnAfterClose |
OnDestroy |
All have been renamed according to the convention used by frameworks like UIKit or React:
Before Hook | After hook |
---|---|
WillOpen |
DidOpen |
DidRender |
|
WillClose |
DidClose |
DidDstroy |
SweetAlertOptions
propertiesInputLabel
CustomClass.ValidationMessage
sweetalert2
to 10.5.1
Microsoft.AspNetCore.Components
to 3.1.9
Microsoft.AspNetCore.Components.Web
to 3.1.9
Webpack 5 is now used behind the scenes to create the JavaScript component of the wrapper, which uses more modern JavaScript syntax for slightly smaller file sizes.
NB: The IE11 Compat version wich contains some polyfills still uses the more traditional JS syntax.
In this major release, no breaking changes have been made in the API surface. However, the underlying SweetAlert2 library has changed the HTML structure of the loader.
For the sake of customization, the loader has been separated from the confirm button into its own DOM element (
<div class="swal2-loader"></div>
).As a part of that breaking change, there's a new API param
loaderHtml
which allow to set custom HTML, e.g. SVG icon inside of the loader.
SweetAlertOptions
propertiesShowDenyButton
DenyButtonText
DenyButtonColor
DenyButtonAriaLabel
FocusDeny
CustomerClass.DenyButton
SweetAlertResult
and SweetAlertQueueResult
propertiesIsDenied
SweetAlertService
methodsSwal.ClickDenyAsync()
NB: There is no Swal.GetDenyButtonAsync()
method as methods which return HTMLElements are not included in the wrapper library.
As part of the breaking change in sweetalert2@10
there is a new options property to set custom HTML for the loader.
SweetlertOptions
propertiesLoaderHtml
Introduced in [email protected], there is a new options property to set the color of the popup icon.
SweetlertOptions
propertiesIconColor
sweetalert2
to 10.1.0
@sweetalert2/themes
to 4.0.0
For more information, read the sweetalert2 v10.0.0 release.
sweetalert2
to 9.17.1
This list of changes was auto generated.