Comments (17)
This feature has been added in the v5.0.0 release. (#1446) (#1437)
See the README for more details.
from razor.sweetalert2.
This is an interesting suggestion. I'll consider it for the next major version to coincide with sweetalert2@11
.
For now, I'd recommend using the Swal.Mixin({})
, as this is the sort of use case it was created for. Swal.Mixin({})
creates a SweetAlertMixin
object that you can call FireAsync() off of, with whatever options you pass in when the mixin was created.
from razor.sweetalert2.
How does Swal.Mixin({})
affects the current swal?
I used Swal.Mixin({})
yesterday and it works but makes useless the SweetAlertService
current instance since SweetAlertService
doesn't hold the option set up on SweetAlertMixin
from razor.sweetalert2.
I am using hardly the SweetAlertService
and this would make me go a fix it over thousand of files. It doesn't seems a good way for me.
from razor.sweetalert2.
Something you could try perhaps. Create your own scoped service called HeightAutoFalseSweetAlertService
or something similar.
Inject my SweetAlertService
in the constructor. Create the mixin you want. Store it in a local variable of the service class. Then create a FireAsync
method that just passes the config object through to your mixin.
Then, in your components, replace @inject SweetAlertService Swal;
with @inject HeightAutoFalseSweetAlertService Swal;
It could look something like this
public class HeightAutoFalseSweetAlertService {
private SweetAlertMixin _heightAutoFalseMixin;
public HeightAutoFalseSweetAlertService(SweetAlertService originalSwalService)
{
_heightAutoFalseMixin = originalSwalService.Mixin(new SweetAlertOptions {
HeightAuto = false
});
}
public async FireAsync(SweetAlertOptions options) {
await _heightAutoFalseMixin.FireAsync(options);
}
}
from razor.sweetalert2.
I see but still needs to be replaced on all components.
Why can't we have that mixing option in the services.AddSweetAlert2();
?
I haven't read all the source code but does this will take huge refactorization?
This is what we need to expose
Razor.SweetAlert2/Services/SweetAlertMixin.cs
Line 341 in 75037f6
from razor.sweetalert2.
I won't be exposing that method, as I have no intention of extending the API beyond what is provided by the sweetalert2
library.
I'll look into being able to set defaults at Startup, but that will come with v5
from razor.sweetalert2.
I took a deep look into the source code.
I think we just need to overload AddSweetAlert2
with SweetAlertOptions
and SweetAlertService
constructor with SweetAlertOptions
and chain down those settings.
from razor.sweetalert2.
@Basaingeal The MVP!
from razor.sweetalert2.
The global options are not working it's still setting the auto height on the body
from razor.sweetalert2.
Can you share the method call that is resulting in this? Your FireAsync call and the SweetAlertOptions that are being passed in?
from razor.sweetalert2.
await SweetAlertService.FireAsync(null, ResourceManagerLocalizer[Response?.Response?.Message ?? "TransactionCompletedSuccessfully"], SweetAlertIcon.Success);
from razor.sweetalert2.
from razor.sweetalert2.
I am not passing any options at all I am using the overload method with only title, message and icon.
from razor.sweetalert2.
Yes. That is documented functionality. If you don't call the method with an options object on the C# side, it won't call the method with an options object on the JavaScript side.
For example Swal.FireAsync("Hello World")
in C# interpolates to Swal.fire("Hello World")
in JavaScript, while Swal.FireAsync(new SweetAlertOptions("Hello World")
in C# will interpolate to Swal.fire({title: "Hello World"})
in JavaScript. If you call a method that doesn't use options, no default options can be applied.
from razor.sweetalert2.
I see. Will try again tomorrow.
from razor.sweetalert2.
It worked! Thanks!
from razor.sweetalert2.
Related Issues (20)
- How to stop the timer when toasted? HOT 3
- Please may you provide documentation on how to use Html with PreConfirm? HOT 2
- 'IServiceCollection' does not contain a definition for 'AddSweetAlert2' HOT 5
- Dev Dependencies HOT 1
- FireAsync with SweetAlertOptions not working with custom JsRuntime serialization HOT 3
- 'CurrieTechnologies' was undefined Error HOT 11
- Can't inject 'SweetAlertService' on Razor Component HOT 1
- Is there a similar library for .NET Core MVC? HOT 2
- .Net 6 Support HOT 5
- 5.1.0 Throwing JSDisconnectedException after browser closed, left then reopened HOT 1
- Example is incorrect
- Nugget not working HOT 1
- Target property in SweetAlertOptions doesn't appear to be working HOT 1
- razorpage .net6 HOT 9
- How to add custom inputs?
- 'CurrieTechnologies' was undefined HOT 3
- Interface IAsyncSweetAlertService: public instead of protected
- Bug Color - Razor/Blazor HOT 3
- showloadingAsync loading text HOT 2
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 razor.sweetalert2.