Questions tagged [javascript]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
6 votes
1 answer
320 views

How to trigger updateElements when hide modal?

Is it possible to refresh an element's list when closing a modal? I have a modal ready with: onHide : function(){ //but all what I tried doesn't work here //1: This will do the trick, but ...
Alex's user avatar
  • 427
5 votes
1 answer
4k views

Loading javascript on specific sections/pages

What is the recommended way to add section specific javascript to entry pages? I need to make some 3rd party api calls front end for currency conversion but I want to only use it on a specific ...
joomkit's user avatar
  • 1,994
5 votes
1 answer
2k views

Update Commerce Cart using Ajax

Is there a way to update the cart using ajax? I've tried something like: $('span.quick-cart-add>p>a').click(function(e){ e.preventDefault(); var data = {}; ...
taylor's user avatar
  • 1,118
5 votes
1 answer
226 views

Are there callbacks for elementSelect macro?

I am writing a custom field type that makes use of Craft's asset selector, and saw that there is an elementSelector macro (in includes/_forms). I want to be able to do some things onSelect, but I ...
kcolls's user avatar
  • 608
4 votes
3 answers
2k views

JS templating in Craft CP

I'm writing a plugin where I need to render some semi-complex HTML clientside at runtime (all inside the CP). Does Garnish (or any other library/framework/JS-thingamabob shipped with Craft) offer any ...
Mats Mikkel Rummelhoff's user avatar
4 votes
1 answer
574 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 %}<...
Matthias Redl-Mann's user avatar
4 votes
2 answers
4k 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 ...
Ben Croker's user avatar
  • 7,226
4 votes
3 answers
1k 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 ...
lotech's user avatar
  • 43
4 votes
1 answer
524 views

Can Garnish be extended to allow plugins to use custom keyboard shortcuts?

For example, when editing an entry cmd + s saves the entry. Is there an easy way to extend Garnish to allow for my plugin to listen for custom keyboard shortcuts?
Jason McCallister's user avatar
3 votes
2 answers
1k views

Is it possible to disable dev output in a template when devMode is true?

For example the template just outputs JSON, which breaks when Craft's devMode logging is added.
Russ Back's user avatar
  • 1,503
3 votes
2 answers
707 views

Access add and remove events with the Craft Element Selector?

Is there any way to access an event, and trigger some function, when an element is added / removed with the Craft Element Selector logic available in Garnish? I am working on a custom field type and ...
Sam Hibberd's user avatar
3 votes
1 answer
336 views

Trigger Task Status Icon

I have a plugin that starts a task and subtasks from a CP widget AJAX call. The tasks are running without a hitch, but for some reason on production, the icon does not appear when the tasks start ...
Aaron Berkowitz's user avatar
3 votes
2 answers
196 views

Is there an accessible callback when Craft.EntryTypeSwitcher is run?

When a user switches Entry Types in the control panel, Craft.EntryTypeSwitcher is trigged which in turn triggers onTypeChange. Is there callback that a plugin can access to run some additional ...
Peter Tell's user avatar
  • 1,828
3 votes
1 answer
219 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. ...
foamcow's user avatar
  • 2,019
3 votes
2 answers
1k 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": "...
Hellyar's user avatar
  • 911
3 votes
1 answer
1k views

Use Craft.postActionRequest in frontend template

Until now I've always done backend plugin development but my next task is to create a homepage with craft. To make an Ajax request I used Craft.postActionRequest but if I try this in my frontend ...
Robin Schambach's user avatar
3 votes
2 answers
2k 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 ...
mrsmn's user avatar
  • 721
3 votes
1 answer
317 views

Listen for checkbox check event for assets table and modify action trigger menu item

I am able to listen to an event when the user checks the checkbox in the assets table. This is within my js file init file that extends garnish: Garnish.Base.extend When the checkbox is selected, I ...
Brad's user avatar
  • 487
3 votes
1 answer
183 views

Swapping Hogan for other JavaScript template engine in the SearchPlus plugin

For a JavaScript novice like myself, what steps would be involved in swapping out the hogan.js templating framework for something else? I have my eye on Swig, which comes with some 'twig-like' filters ...
John Johnson's user avatar
2 votes
3 answers
34k views

Can I set a JS variable to a Twig output tag?

This came out of a previous question I need to set a variable of a tag group that I can reference in jquery for use with a plugin. I'm declaring this variable in a tag so my included js files can ...
Andrea Hall's user avatar
2 votes
3 answers
630 views

Triggering JavaScript from back-end event

I'm building a plugin and want to trigger some JavaScript on an event being fired (eg an entry being saved). What is the best way to achieve this? Coming up short looking through the documentation and ...
Cole Henley's user avatar
  • 1,741
2 votes
2 answers
4k 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', ...
Adam McCombs's user avatar
  • 1,685
2 votes
2 answers
156 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 ...
cannon303's user avatar
  • 309
2 votes
1 answer
3k 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!
Sander Van Keer's user avatar
2 votes
1 answer
1k views

AJAX page transitions with history.pushState

I'm a new craft user (previous EE user). trying to follow Zack Spear's directions (https://designbycosmic.com/journal/craft-cms-ajax-page-transitions-with-history-pushstate) for how to setup Ajax page ...
Benek Lisefski's user avatar
2 votes
1 answer
2k views

Can you pass a variable with includeJsFile?

Can you do something similar to using "with" in twig's include tag (http://twig.sensiolabs.org/doc/tags/include.html), but instead with includeJsFile? I am using a plugin to filter my entries by ...
Andrea Hall's user avatar
2 votes
2 answers
107 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 ...
Azazel's user avatar
  • 101
2 votes
2 answers
2k views

Add listener to dynamic html elements

I have a field type that I need to initialize. When the page loads I can use code like the following to handle certain behaviors of the field: $('.myfieldwrapper').each(function() { new Craft....
Ben Parizek's user avatar
  • 13.3k
2 votes
1 answer
679 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 ...
michael's user avatar
  • 228
2 votes
1 answer
227 views

How would I trigger updateElements for BaseElementIndex from a plugin's JavaScript?

If I wanted to update the Elements listing based on an action taken from a plugin, would it be possible to do this? Setup: We're on an Elements listing page. We filter the results with a search ...
Peter Tell's user avatar
  • 1,828
2 votes
1 answer
537 views

Escaping quotes of an entry string used inside a script tag

How can I display an entry string, with included special characters (like single and double quotes) , inside a script tag without translating these special characters into html entities but escaping ...
Samuel's user avatar
  • 69
2 votes
1 answer
386 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 ...
Bryce's user avatar
  • 251
2 votes
2 answers
877 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 ...
Jorge Sosa's user avatar
2 votes
1 answer
81 views

Is there a JS event triggered when a new widget is created?

Pretty straightforward problem... On the dashboard, I click "New Widget". I select "My Custom Widget" type. A new instance of "My Custom Widget" appears on the dashboard, ready to be edited. How can ...
Lindsey D's user avatar
  • 23.9k
2 votes
1 answer
199 views

JS - Determine that an entry is unsaved?

I've created a custom fieldtype... which is basically a button that triggers an AJAX action. When I add this field to my section, I can click the button while I'm editing an entry to perform an action....
Lindsey D's user avatar
  • 23.9k
2 votes
1 answer
452 views

Missing javascript .map files

When I view the browser console whilst viewing the Dashboard for instance, I get a whole load of 404s for Javascript .map files. For example on a fresh update to v2.3 I get this lot reported as ...
Steve Holland's user avatar
2 votes
2 answers
607 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, ...
Ian's user avatar
  • 41
2 votes
1 answer
404 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 ...
Ryan Sneesby's user avatar
2 votes
1 answer
860 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 ...
Clive Portman's user avatar
2 votes
1 answer
161 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 ...
Rodrigo Passos's user avatar
2 votes
2 answers
16k 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 ...
Anta's user avatar
  • 21
2 votes
1 answer
677 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 ...
Andrea DeMers's user avatar
2 votes
1 answer
237 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 ...
Jose's user avatar
  • 103
2 votes
1 answer
348 views

Javascript event on save for custom field

I have implemented a custom field type. Is there any way to register a javascript event handler that is called before my custom field is saved?
Kristian J.'s user avatar
2 votes
1 answer
339 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 ...
Robin Schambach's user avatar
2 votes
1 answer
259 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 ...
Ben Parizek's user avatar
  • 13.3k
2 votes
0 answers
922 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 ...
Christian Kulbe's user avatar
2 votes
0 answers
166 views

Live Preview not showing correct content when using single page app with JavaScript

So I am creating a website using Craft with JavaScript for making it a single page app. I load my layout which then calls the pages which works well. The only problem is that when viewing pages ...
nickGR's user avatar
  • 197
2 votes
0 answers
46 views

JavaScript equivalent to "namespaceInputName"?

Is there a JavaScript equivalent to namespaceInputName? My fieldtype settings are doing some interesting JavaScript gymnastics. Part of the process involves creating an array on the fly (so when the ...
Lindsey D's user avatar
  • 23.9k
1 vote
2 answers
1k 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 ...
Justin Kendall's user avatar