Questions tagged [javascript]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1
vote
1answer
29 views

404 Error Controller Action From Jquery But Not Url

I'm able to call my controller action directly from a url in the browser and get the proper response but when I call it from a page with js I get a 404 error. I'm working off the solution found here ...
1
vote
1answer
33 views

Loading JavaScript on Template Load

I'm working on a kiosk-type plugin which will cycle through all news entries, beginning upon template (or page) load. It needs to load a JavaScript ajax script for this on page/template load. Would ...
1
vote
1answer
20 views

Showing and hiding details (price, sale price, sku etc)when product variant is selected on details page

I currently have price, sku and variant title swapping when clicking between variants on a products details page. This works with AlpineJS and looks something this. https://codepen.io/amasci/pen/...
2
votes
1answer
41 views

Re-initialize / layout Masonry after a sprig change

I've got Sprig set up to filter entries by a few categories. I'm trying to re-layout Masonry JS after this update takes place. For starters, I add Masonry to the window variable (defined as global in ...
3
votes
1answer
252 views

Interpret TWIG's {% js %} as <script> in PHPStorm

Does anyone know how to get PHPStorm interpret {% js %} as <script> for correct syntax highlighting in PHPStorm? Background: I'am always doing this: {% js at endBody %} {% if false %}<...
1
vote
1answer
47 views

Populating Matrix Blocks with JavaScript

I need to populate a matrix block field with JavaScript in the control panel. I've got the data ready, but i can't figure out how to add it. I've located a function called addBlock() in MatrixInput.js ...
0
votes
0answers
118 views

Barba.js (with gsap) 'leave' and 'enter' hooks not working in Craft 3 - same code works in WordPress

The below code (Barba/gsap) works as expected in WordPress, but in Craft 3 only the 'once' (i.e. not the 'leave' and 'enter') hooks fire. There are no errors or anything unusual in the Barba debug ...
1
vote
1answer
150 views

Output javascript inside twig variable

I am using the Enupal Stripe Payments plugin to pass line items to Stripe. The line items get passed in an array. I want to use a javascript cart to hold the items in local storage, reformat that and ...
1
vote
1answer
64 views

How to include Inline JavaScript?

Is there any way to add javascript in craft
0
votes
0answers
23 views

Re- Arrange the Address-Country select field

I try to increase the usability of my shipping address input form. The country list is pretty impractical. I'd like to have the most used countries on top. Dropdown List: Switzerland Germany UK USA ---...
1
vote
1answer
401 views

How to include external JavaScript in place?

We include an external script from a vendor and the URL doesn't end in .js. It returns JavaScript that creates a widget in place. I was able to fake it out by adding a '&js=.js' parameter but it ...
1
vote
2answers
129 views

How to get an input value without refreshing with twig?

One way to read a dynamically inserted value is to refresh the page and get it in a twig variable through the url, something like this: {% set amount = craft.app.request.getQueryParam('amount') %} ...
1
vote
2answers
21 views

Plugin Settings Color Input Javascript Event Listeners

Is it possible to attach JavaScript event listeners to the colour input field in a plugin's settings page, so that when a user selects a colour with the picker I can run an AJAX request?
1
vote
0answers
36 views

Sprout Forms Recaptcha js error - everything flagged as spam

I'm using the Google reCAPTCHA plugin with Sprout forms. I'm trying to use an invisible reCAPTCHA badge, but I'm getting a js error on page load: Unhandled Promise Rejection: TypeError: null is not an ...
1
vote
1answer
294 views

Input and Use Twig Variable in External JS Script Across Different Pages

I have created a _layout.twig file which acts as my base to hold content on the page -> _layout.twig: <!DOCTYPE html> <html lang="{{ craft.app.language }}"> <head> ...
1
vote
1answer
48 views

javascript module question

Hi hope you can help with this and hoping it's simple. I need to write a javascript module and would like to use the js tag: {% js %} //script here {% endjs %} This is good because it only ...
2
votes
1answer
401 views

JS login form on different domain and handling the CSRF token

Having sorted out the CORS issue and succesfully logging into Craft from a different domain using Javascript, I've now turned CSRF protection back on. I've got a module returning the CSRF token name ...
0
votes
0answers
113 views

How to load more entries of a category on that category's page with Element API?

Following up on previous questions of mine: How to use multiple different instances Element API "Load More" button? I have a website that utilizes the "load More" (button) method ...
1
vote
1answer
66 views

How to use multiple different instances Element API "Load More" button?

Following up on a previous question of mine: How to skip the first few entries in a "load more" scenario with Element API? I have a website that utilizes the "load More" (button) ...
1
vote
1answer
47 views

How to skip the first few entries in a "load more" scenario with Element API?

I have a website that uses a "load more" button. The process for this button can be found here: http://craftsnippets.com/articles/infinite-scrolling-and-lazy-loading-with-craft-cms I made it ...
1
vote
1answer
581 views

Load More Entries Button

I am trying to make my entry loop have a load more button, and not sure how to do it. I tried the method from http://craftsnippets.com/articles/infinite-scrolling-and-lazy-loading-with-craft-cms but I ...
0
votes
0answers
22 views

Undefined this.$overflowTabBtn.data(...) initTabs Craft.js:11326:51

I'm getting this error on one Solspace calendar (2.x) event entry form, but not another. The only difference seems to be two asset fields, and one entry reference field. It's the only page the error ...
1
vote
1answer
69 views

Click counter for links (craft v2)

So I'm new to PHP and ok with Javascript. I have a page on my site with a long list of external links, would it be possible to add a counter to be displayed next to each link that shows how many times ...
2
votes
2answers
449 views

How can I get cookies that were set in javascript from a twig template? [NEW]

This question was already asked a few years ago, and the way of doing it was through a plugin. I was wondering if there is a way of doing it just using Craft and Twig. I set up a cookie using ...
1
vote
1answer
492 views

Ajax post request front-end csrf token

I'm trying to make a simple post request with ajax to a controller in plugin. The problem I'm having is that I always get a 400 Bad request because I don't send a valid CSRF Token. But I can't figure ...
1
vote
1answer
53 views

Access table from Globals in script

In the Globals I have a field which is of type table. I was trying to access this table in the javascript in order to get the values of particular rows. <script> var myTable = "{{ ...
1
vote
2answers
911 views

Can a plugin add JS or CSS to the control panel in Craft 3?

I want entries in a specific PlainText field for a named group to be pre-filled with random content. I am aware of the https://github.com/lukeyouell/craft-randomkeygenerator plugin and am aware that I ...
1
vote
1answer
83 views

Craft 2, MySQL database, Twig, JavaScript files

I have created in Craft 2 CMS, under the profile of users (ex. parents), new tab for (children), where parents can fill in there children information. The data is saved in a database under the ...
0
votes
1answer
148 views

For loop through custom field in JavaScript

I'm using a script to animate four sets of numbers on a page. I would like the numbers to be editable from within the admin (a SuperTable field). Currently I have this: <ul class="counters"> ...
1
vote
0answers
39 views

Can scripts loaded as ES Modules work with Live Preview?

How can a script loaded as an ES module be reinitiated after changes are made in Live Preview? In my experience a script loaded as a module is executed the first time Live Preview is opened, but then ...
2
votes
2answers
101 views

How can I add Google MarkerClusterer library to Smart Map?

I started to work with Craft CMS a couple month ago, I have a client that wants to have a clustered map, I went over Smart Map documentation but I couldn't find anything about on how to add Google ...
1
vote
1answer
188 views

Setting a new / override shippingAddress via axios

I am trying to change/set a customers shippingAddress via axios It does work e.g. for setting the shippingMethod or the quantity for a product. However if i want to set a new shippingAddress the ...
1
vote
1answer
143 views

Setting Google maps circles using Smart Map plugin

So, I'm trying to set circles around marker locations using Smart Map and some JS. I've got the following which gives no errors, but outputs no circles. $(function () { $.each( smartMap.marker, ...
1
vote
0answers
275 views

How can I edit multiple entries via multiple front-end forms using Vue.js?

I found this post. However, writing a plugin in currently not an option, and I'd like to do this with Vue.js since I'm already using it for form validation & other stuff. Also, this involves ...
1
vote
1answer
117 views

includeJs not consistently working

Using Craft 2 and I have a Matrix Block which can contain a carousel item, which uses JS/jQuery. Because the content editor can add multiple instances of this Matrix Block I can’t set up these ...
1
vote
1answer
64 views

Can I add custom JS to Sprout Form?

I'd like to be able to attach custom JS to a Sprout Form which can be managed in the form builder. I need to add logic that will switch the email address of the recipient based on a choice from a ...
3
votes
1answer
205 views

Setting the position of a Smart Map marker on the front end

I'm using Smart Map in a front end entry form and trying to set the position of a marker as the user enters their address. I can get the lat/lon lookup working but I'm stumped with the marker itself. ...
1
vote
1answer
677 views

Make an Ajax call to plug-in controller

I am trying to send data to my plug-in controller using jquery $.post() method. here is my form: <form method="post" action="" accept-charset="UTF-8" id="testForm"> {{ csrfInput() }} <...
1
vote
2answers
375 views

Verbb Comments plugin - Can't see comment replies

I recently installed Verbbs Comments plugin on my Craft site, which seems all well and good except that I can't toggle the comment replies. ('2 comments' when clicked does nothing) Everything else ...
1
vote
1answer
163 views

Plugin field-type not getting javascript variable?

Updating a plugin from Craft 2 to Craft 3, so this logic used to work. The plugin has a field-type which is a button. When clicked, the button does stuff depending upon another field. That handle(ID) ...
1
vote
1answer
138 views

Garnish event when changing category group

When I am on the categories index (admin/categories), is there a Garnish event that fires when you select a different category group in the sidebar? I want to add some custom JS after the AJAX request ...
1
vote
1answer
78 views

How to initiate a date picker when template is loaded remotely from controller action

I have a controller action which returns JSON with a rendered template. This template uses date picker form fields. How can the date picker JS be initialized since the html is returned through JSON. ...
1
vote
1answer
695 views

How can I reload the Live Preview Iframe window using JS

I tried to reload the iframe window using JS but haven't had any luck getting the lp-iframe iframe element, I was thinking I could do it using the Window.Craft object but not sure how? setTimeout(()=&...
0
votes
1answer
376 views

Ajax pagination not loading last entries if not equal to pagination number

I've got ajax working on a page but if the number of articles is not exactly 3 (this is the pagination limit) then the remaining 1 or 2 entries do not get loaded. I'm not sure why or how to resolve ...
2
votes
1answer
291 views

Craft 3 js - extend the field layout designer field settings

I would like to have the ability to include a custom option in the field layout designer field settings. There is already a plugin for Craft 2 that uses this feature Relabel for Craft And I would ...
1
vote
1answer
408 views

Craft 3 - custom callback after Garnish onDragStop

I would like to trigger a custom javascript function after an element in a matrix block was moved in the matrix but I'm not sure how to attach the event without changing the MatrixInput.js. So far I'...
1
vote
1answer
807 views

How to set up a social media feed with vue and axios

What I need is a social media stream with posts with the Hashtag mnbasel form Instagram, Facebook and Twitter. I couldn’t find any good tutorial. Hopefully someone can tell me what I miss or lead me ...
2
votes
1answer
178 views

How to extend Craft.BaseElementIndex for a custom Element Type

I have a custom Element and need to modify the Element Index page. I'm attempting to extend Craft.BaseElementIndex and register the extended class on my Element Index Page. I'm working on a plugin for ...
1
vote
1answer
64 views

Programmatically Setting Entry Type Via Javascript

At the moment I'm trying to create a script that is supposed to be run (by chrome extension) on page load (of the new entry page) that with automatically set the entry type. The name of the entry type ...