Closed linktoaqeel closed 4 years ago
Thank you for filing this issue. In order for us to investigate this issue, please provide a minimalistic repro project (ideally a GitHub repo) that illustrates the problem. Please note, that if a library you're using is trying to mutate the DOM on its own, that can break Blazor. You can read more about this at: https://docs.microsoft.com/en-us/aspnet/core/blazor/call-javascript-from-dotnet?view=aspnetcore-5.0#use-of-javascript-libraries-that-render-ui-dom-elements
Thank you, @mkArtakMSFT for checking this thread.
I have uploaded my sample repository on Github. As I have mentioned that I am using the Select2 jquery plugin in my project and because of this plugin Blazor model variable is not updating if the user makes any selection from the drop-down list or changes the date range from the calendar plugin.
I hope the uploaded repo would replicate the same issue and help to resolve this issue. Waiting for your feedback
Hi @linktoaqeel
In general, jQuery plugins that mutate the DOM shouldn't be expected to work automatically with any SPA framework (whether that's Blazor, React, Angular, Vue, etc.). This is because SPA frameworks take control over their own DOM rendering and if some external code mutates the DOM, they don't know what's going on with it. This is covered in the docs at https://docs.microsoft.com/en-us/aspnet/core/blazor/call-javascript-from-dotnet?view=aspnetcore-5.0#use-of-javascript-libraries-that-render-ui-dom-elements
Rather than relying on jQuery plugins, it's recommended to build the UI you want using components from the SPA framework you're using (e.g., for Blazor, use Blazor components, or for React use React components).
In more advanced cases you can use JS interop to render DOM contents using external JS libraries but you will have to take care of keeping that independent of the DOM contents rendered by your SPA framework, and write your own logic to keep the two in sync. This is how people implement SPA-framework-specific wrappers for libraries like Select2.
This issue has been resolved and has not had any activity for 1 day. It will be closed for housekeeping purposes.
See our Issue Management Policies for more information.
I am using the AdminLTE template in my Blazor wasm application. The template is working fine but I am having an issue with input fields binding. I have a data filtering form and the application should apply the selected filter values to fetch the new data. I have to change the "on document ready" function to the below code in the index.html file to make the jquery plugin working.
In my razor component, I am calling the above-mentioned function as shown below:
I have bind the HTML tags in my razor component with C# variables:
If I don't call the "onBlazorReady" function then data binding is working but the plugins are not reflecting as expected. I am using different controls such as date range control with the calendar and multiple selections for choosing departments. So I need to call the "onBlazorReady" function. But when I invoke this function then data binding stops working.
When the user clicks on the "Apply" button, I want to get the selected values and load data based on applied filters.