Can someone explain to me how to configure alpinejs in an ASP.NET Core MVC project and use it in a my .cshtml files?
I have already run npm install alpinejs and I have already imported it into my index.cstml file
<script src="~/node_modules/alpinejs/dist/alpine.js"></script>
However I have a problem when I make #click
<button class="outline-none focus:outline-none border-r border-gray-200 w-10 h-10 hover:text-indigo-500 active:bg-gray-50"
#click="format('bold')">
<i class="mdi mdi-format-bold"></i>
</button>
Thank you for help
the # is already a reserve symbol in asp.net, so you can escape it with ##click or use the longer binding syntax in Alpine of x-on:click
Related
I am trying this sample bootstrap dropdown code. There is no error but my dropdown is not working
I have installed jquery-popper, jquery and bootstrap 5
<div class="dropdown">
<button class="btn btn-secondary dropdown-toggle" type="button"
id="dropdownMenuButton1" data-bs-toggle="dropdown" aria-
expanded="false">
Dropdown button
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenuButton1">
<li><a class="dropdown-item" href="#">Action</a></li>
<li><a class="dropdown-item" href="#">Another action</a></li>
<li><a class="dropdown-item" href="#">Something else here</a></li>
This is how my angular.json looks like
` "styles": [
"./node_modules/#angular/material/prebuilt-themes/deeppurple-
amber.css",
"./node_modules/bootstrap/dist/css/bootstrap.css",
"node_modules/bootstrap/dist/css/bootstrap.min.css",
"src/styles.css",
"node_modules/slick-carousel/slick/slick.scss",
"node_modules/slick-carousel/slick/slick-theme.scss"
],
"scripts": [
"node_modules/jquery/dist/jquery.min.js",
"node_modules/bootstrap/dist/js/bootstrap.min.js",
"node_modules/slick-carousel/slick/slick.min.js"
]`
I have also included "node_modules/#popperjs/core/dist/umd/popper.min.js", in script array and tried but nothing happens. Am I missing something here
What version of bootstrap are you using? In case you are using v5, you should not import jQuery, as Bootstrap dropped jQuery in its latest version.
Our latest release, Bootstrap 5, focuses on improving v4’s codebase with as few major breaking changes as possible. We improved existing features and components, removed support for older browsers, dropped jQuery for regular JavaScript, and embraced more future-friendly technologies like CSS custom properties as part of our tooling.
(Taken from the Bootstrap About Page)
For some components (e.g. Popovers, Tooltips), you will need Popper.js. Make sure to include it by either passing both Bootstrap and Popper.js into the scripts section or just include the complete Bootstrap bundle which contains Popper.js like so:
"scripts": [
"node_modules/bootstrap/dist/js/bootstrap.bundle.js",
// other script files ...
],
You can also use the minified version of the bundle ([...].bundle.min.js)
i am working on my new project and technology stack is: laravel 8 + Livewire V2 + Jetstream, to create a single page application (SPA). but I am still confused if its possible SPA in my selected technology stack or not.
I know Livewire no longer supports Turbolinks out of the box so they provided Turbolinks adapter. I have followed the documentation but seems like its not working. please help me to understand the issue and let me know if SPA is possible or not in Livewire version 2.
here is my code:
<div class="min-h-screen bg-gray-100">
#livewire('navigation-menu')
<!-- Page Heading -->
#if (isset($header))
<header class="bg-white shadow">
<div class="max-w-7xl mx-auto py-6 px-4 sm:px-6 lg:px-8">
{{ $header }}
</div>
</header>
#endif
<!-- Page Content -->
<main>
{{ $slot }}
</main>
</div>
#stack('modals')
#livewireScripts
<script src="https://cdn.jsdelivr.net/gh/livewire/turbolinks#v0.1.x/dist/livewire-turbolinks.js" data-turbolinks-eval="false"></script>
Livewire Version 1 supported Turbolinks internally. Livewire Version 2 has removed internal support and extracted it into this plugin.
The goal of this livewire version 2 is to provide full Turbolinks/Turbo support in Livewire.
add hotwired/turbo package on your layout below #livewireScripts
add livewire/turbolinks package on your layout below hotwired/turbo package
#livewireScripts
<script type="module">
import hotwiredTurbo from 'https://cdn.skypack.dev/#hotwired/turbo';
</script>
<script src="https://cdn.jsdelivr.net/gh/livewire/turbolinks#v0.1.x/dist/livewire-turbolinks.js" data-turbolinks-eval="false" data-turbo-eval="false"></script>
You need to install Turbolink module first, Please go Turbolinks documentation Here.
Support for Turbolink has been removed in Livewire 2. So you need to add an extra JS script to make it work.
More here => https://github.com/livewire/turbolinks
Just add this after your livewire script:
<script src="https://cdn.jsdelivr.net/gh/livewire/turbolinks#v0.1.x/dist/livewire-turbolinks.js" data-turbolinks-eval="false" data-turbo-eval="false"></script>
Example:
#livewireScripts
<script src="https://cdn.jsdelivr.net/gh/livewire/turbolinks#v0.1.x/dist/livewire-turbolinks.js" data-turbolinks-eval="false" data-turbo-eval="false"></script>
I'm trying to make different divs show up according to the selected radio button option using v-model and v-show but, even though they stay hidden when the page is loaded as they should, they don't show up when a radio button is selected.
This code is a Vue component inside of a Laravel project. When I try this same code on https://jsfiddle.net/, using only Vue, it works exactly how it should. But when I try it inside my Laravel project, it doesn't work.
Component's HTML (don't mind the id and name values):
<div id="app">
<div>
<span><strong>*</strong> options </span>
<div>
<input type="radio" id="grerjSim" name="grerj" value="showYes" v-model="showOption">
<label for="grerjSim"> yes </label>
</div>
<div>
<input type="radio" id="grerjNao" name="grerj" value="showNo" v-model="showOption">
<label for="grerjNao"> no </label>
</div>
<div v-show="showOption === 'showYes'">
<span><strong>*</strong> Lorem ipsum dolor sit amet. </span>
<input type="text" required>
</div>
<div v-show="showOption === 'showNo'">
<label for="grerjMotivo">No
<select id="grerjMotivo">
<option>Lorem ipsum dolor sit amet.</option>>
</select>
</label>
</div>
</div>
</div>
Component's JS:
<script>
new Vue({
el: '#app',
data: {
showOption: value=""
}
})
</script>
Any help would be great :)
I noticed that your Vue-related JavaScript is inside its own <script> tag, which I assume means you're writing the Vue code in your Blade template.
While you can get Vue apps working that way, it's easier to manage if you keep your JavaScript contained in the source files located in resources/js. There is even an example already there for you to customize.
Also, when I asked if you checked your console for any errors, I meant your web browser's developer tools console. If you haven't checked that yet, it may hold a very obvious clue in the form of a specific error.
Here are a couple errors that your console might have:
ReferenceError: Vue is not defined
This means you added the Vue app code (new Vue({ ... })), but no other JavaScript including the Vue library, so the code doesn't know what Vue is.
[Vue warn]: Property or method "showOption" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property.
If you tried to fix the undefined Vue error above by running Laravel Mix and adding a <script> tag for the built file, you might see this. That's because the default Mix source code has an example Vue app targeting #app already, so the two are conflicting and the one in app.js is winning.
You'll either want to remove your Blade file Vue app and customize the default one in app.js (recommended), or remove the app.js one and keep the Blade file.
Official documentation on using Laravel Mix with JavaScript.
not sure why my magento site
all links broken, My check out button link showing me like this error
<form "="" getformkey="" varnishcache="" www.alphacateringequipment.com.au="" https:="" action="https://www.alphacateringequipment.com.au/checkout/cart/add/uenc/aHR0cHM6Ly93d3cuYWxwaGFjYXRlcmluZ2VxdWlwbWVudC5jb20uYXUvYmV2ZXJhZ2UvYWNjZXNzb3JpZXM,/product/3704/form_key/<esi:include src=">/" method="post" id="product_addtocart_form_3704">
<button onclick="productAddToCartForm_3704.submit()" class="form-button listing_cart-btn">ADD TO Cart</button>
</form>
and also my site drop down menu not working more
if any one know this
Please help me out.
thank you
Try below code.
<form name="text" getformkey="<?php echo Mage::getSingleton('core/session')->getFormKey(); ?>" varnishcache="" www.alphacateringequipment.com.au="" https:="" action="https://www.alphacateringequipment.com.au/checkout/cart/add/uenc/aHR0cHM6Ly93d3cuYWxwaGFjYXRlcmluZ2VxdWlwbWVudC5jb20uYXUvYmV2ZXJhZ2UvYWNjZXNzb3JpZXM,/product/3704/form_key/<esi:include src=">/" method="post" id="product_addtocart_form_3704">
<button onclick="productAddToCartForm_3704.submit()" class="form-button listing_cart-btn">ADD TO Cart</button>
</form>
It will broken due to form key not passed by In Version of Magento.
<div class="btn-group">
<button class="btn dropdown-toggle" data-toggle="dropdown"> Reviews </button>
<button class="btn dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></button>
<ul class="dropdown-menu">
<li>testuser 2012/08/12 12:25:42:836 PM</li>
<li>testuser11 2012/08/13 12:25:42:836 PM</li>
</ul>
</div>
I am using bootstrap.min.js v2.0.4 and jquery 1.7.2, tried with jquery 1.8.0 and 1.7.1 with same results
I have this js code in tbspopover.js -
jQuery(function(){
$('a[rel=popover]').popover();
});
Script Order
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<script src="/vendor/bootstrap.min.js"></script>
<script src="/js/views/tbspopover.js"></script>
The js function to enable popover was called before the element was added to DOM. The DOM element wasn't added until after ajax call was done. Found a tip here
With an older Version (2.0.2) of Bootstrap it should work.
You can find a working example here.
Older Versions of Twitter Bootstrap can be found on Github here.
I had a similar issue, it was because font-size of .btn-group was set to ZERO!!