Questions tagged [javascript]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0
votes
0answers
7 views

trigger javascript when block is added to matrix or supertable

I need to run javascript to modify a field-input when the user edits an entry and adds a block/row to a matrix or super-table field. Is there an event to listen on or some callback to hook in? ...
2
votes
1answer
508 views

Including plugin javascript on the client side

I've created a simple plugin based on the Craft docs with the following directory structure... /craft /plugins /eforms /resources /js ...
1
vote
1answer
84 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 ...
2
votes
2answers
106 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 ...
0
votes
0answers
16 views

Update the element selection in BaseElementSelectInput via Javascript

I am building a javascript helper to assist user to populate some Entry/Category data. For the BaseElementSelectInput widget used in Entry/Category field when editing an entry, is there any way to ...
1
vote
2answers
213 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 ...
0
votes
1answer
134 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
25 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
260 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 ...
2
votes
2answers
220 views

Live Preview Not Updating - No errors found

Okay, first I know this question has been asked - specifically here: Live preview not automatically updating But that suggestion did not help. I have no console errors, no network errors. In fact, ...
1
vote
1answer
52 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
48 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
31 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
49 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 ...
2
votes
2answers
2k views

Craft 3 - ajax request to plugin

This is a pretty simple test before I implement some larger functionality. Eventually this will be just a glorified upload form via ajax. Part 1 - Ajax post $.ajax({ type: 'POST', ...
1
vote
1answer
49 views

Setting Google maps circles using Smartmap plugin

So, I'm trying to set circles around marker locations using Smartmap and some JS. I've got the following which gives no errors, but outputs no circles. $(function () { $.each( smartMap.marker, ...
4
votes
3answers
858 views

Creating environment variable from JSON file

Brand new to Craft here. I'm trying to port across my gulp workflow to Craft and basically everything has gone super smooth. Just one last obstacle due to my lack of knowledge of the Twig templating ...
1
vote
0answers
131 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
77 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
32 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
126 views

Setting the position of a SmartMap marker on the front end

I'm using SmartMap 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
326 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() }} <...
4
votes
1answer
2k views

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

The docs state that {{ craft.request.getCookie(name) }} will not work for cookies that were set in JavaScript, because all cookies in Craft go through some validation to ensure that they aren't ...
1
vote
2answers
6k views

Unexpected token “end of template” of value “” (“end of statement block” expected)

Good afternoon, I'm new in Craft so I installed this step-by-step and I tried to install this theme: https://github.com/duezerouno/0-201 After I did everything, I can see a template error on my site ...
1
vote
1answer
81 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
84 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
54 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
591 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(()=&...
2
votes
0answers
636 views

Content-Security-Policy Header vs. CSRF Token and login.html

My company would use the current version of the Content-Security-Policy header. We have problems with inline JavaScript and would not use MD5 checksums with the policy. Eg: CSRF Token support ...
0
votes
1answer
306 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
217 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
213 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
543 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
105 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
51 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 ...
1
vote
1answer
91 views

How to access Craft.EditableTable instance in CraftCM

I am developing a custom plugin that has a variable setting that can take multiple options. I've decided to use forms.editableTable from Craft's _includes/forms. It does the job great, saving and ...
1
vote
1answer
27 views

How to avoid “Double-instantiating a pane on an element”

Without going into too much detail, I have a plugin where I'm trying to manage two different sets of tabs with some custom javascript. When the object initializes, I need to add a pane from the page ...
1
vote
0answers
496 views

How to access logged in CSRF token?

I’m currently using react as a font end SPA with craft cms as the backend. I’m trying to create user accounts where a user use can sign up and favourite content on the site, using the Like for craft ...
0
votes
1answer
180 views

Dynamic entries limit via dropdown

On a entries (listing) page I'm using pagination and a fixed limit of entries set. I want visitors to be able to select (dropdown) the number of entries that should be listed (limit). I'm not a Java ...
1
vote
2answers
287 views

Update Commerce Cart using Fetch

Hi this is a variation of the question asked here on updating the cart using ajax, instead I'm attempting to use the Fetch API. As a test the form submits properly when submitting in the usual way ...
1
vote
1answer
644 views

How can I pass a JS result into a Twig template?

I've got a frontend form which queries the openstates.org API to return a given set of data objects. Those objects also exist in Craft as entries, and the API data includes a field that serves as a ...
1
vote
1answer
686 views

How do I print a value from Craft/Twig into a Javascript function?

I just want to print a value from Craft into a JavaScript function to filter a dashboard. The function is this: showOnly(filterName, values); I tried this: showOnly('Short Names','{{ entry.title ...
2
votes
1answer
926 views

Local storage in Twig

Quick question: Is it possible to access the browser's local storage in Twig? In JavaScript you would do something like: localStorage.getItem('myItem'); Thanks!
1
vote
2answers
675 views

How Customizable is the Craft Admin Interface?

Could a tool like AngularJS or VueJS or React help in significantly customizing the Craft admin interface? Could it help add additional functionalities? For instance, let's take the example of ...
1
vote
2answers
125 views

How to update front end Craft new row - stuck on JavaScript

I'm building out a front end entry form with a Natrix and everything is coming along fine. However when users create a new row each new row needs to be unique in order to be saved. This is where I'm ...
3
votes
2answers
731 views

How do you use a for loop to output to JS?

I have a map generated in JS. I need to set the country-id and url for each country. Both 'country-idandurlare fields in my Craft categories groupcountries`. { "country-id": "FR", "url": "...
2
votes
2answers
832 views

Translating static text in JavaScript files

I've got some static text that is dynamically being displayed on the frontend with JavaScript. Now considering the site has 3 locales, how do I best translate those static texts? I know I could ...
1
vote
1answer
184 views

Saving Form Data to Plugin Record via Javascript

I am new to Craft plugin development, so I apologize ahead of time for my lack of understanding. I'm working on a plugin that allows the user to "upload" Excel/csv files via the control panel that ...
2
votes
1answer
140 views

Minifying bower_components js files

I am currently using spoeken's gulp workflow (https://github.com/spoeken/gulp-craftcms). Everything works well in development, however, when it comes to production, I can't seem to concat/minify my ...
2
votes
1answer
414 views

How can I validate a Redactor rich text field in a front-end form using the VeeValidate Vue.js plugin?

Scenario I'm using the VeeValidate Vue.js plugin to validate a Craft front-end form that contains a Redactor rich text field. Problem Validation of the rich text field fails because Redactor adds ...