Giter VIP home page Giter VIP logo

Comments (17)

Basaingeal avatar Basaingeal commented on May 28, 2024 1

This feature has been added in the v5.0.0 release. (#1446) (#1437)

See the README for more details.

from razor.sweetalert2.

Basaingeal avatar Basaingeal commented on May 28, 2024

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.

arivera12 avatar arivera12 commented on May 28, 2024

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.

arivera12 avatar arivera12 commented on May 28, 2024

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.

Basaingeal avatar Basaingeal commented on May 28, 2024

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.

arivera12 avatar arivera12 commented on May 28, 2024

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

private SweetAlertOptions Mix(SweetAlertOptions newSettings)

from razor.sweetalert2.

Basaingeal avatar Basaingeal commented on May 28, 2024

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.

arivera12 avatar arivera12 commented on May 28, 2024

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.

arivera12 avatar arivera12 commented on May 28, 2024

@Basaingeal The MVP!

from razor.sweetalert2.

arivera12 avatar arivera12 commented on May 28, 2024

The global options are not working it's still setting the auto height on the body 😢.

image

image

from razor.sweetalert2.

Basaingeal avatar Basaingeal commented on May 28, 2024

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.

arivera12 avatar arivera12 commented on May 28, 2024

await SweetAlertService.FireAsync(null, ResourceManagerLocalizer[Response?.Response?.Message ?? "TransactionCompletedSuccessfully"], SweetAlertIcon.Success);

from razor.sweetalert2.

arivera12 avatar arivera12 commented on May 28, 2024

image

from razor.sweetalert2.

arivera12 avatar arivera12 commented on May 28, 2024

I am not passing any options at all I am using the overload method with only title, message and icon.

from razor.sweetalert2.

Basaingeal avatar Basaingeal commented on May 28, 2024

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.

arivera12 avatar arivera12 commented on May 28, 2024

I see. Will try again tomorrow.

from razor.sweetalert2.

arivera12 avatar arivera12 commented on May 28, 2024

It worked! Thanks!

from razor.sweetalert2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.