Questions tagged [javascript]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
6 votes
1 answer
284 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 ...
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 ...
user avatar
  • 1,900
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 = {}; ...
user avatar
  • 1,108
5 votes
1 answer
222 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 ...
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 ...
user avatar
4 votes
1 answer
400 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 %}<...
user avatar
4 votes
2 answers
3k 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 ...
user avatar
  • 6,341
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 ...
user avatar
  • 43
4 votes
1 answer
503 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?
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.
user avatar
  • 1,503
3 votes
2 answers
657 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 ...
user avatar
3 votes
1 answer
335 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 ...
user avatar
3 votes
2 answers
177 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 ...
user avatar
  • 1,828
3 votes
1 answer
212 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. ...
user avatar
  • 1,999
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": "...
user avatar
  • 891
3 votes
1 answer
993 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 ...
user avatar
3 votes
1 answer
314 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 ...
user avatar
  • 487
3 votes
1 answer
178 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 ...
user avatar
2 votes
3 answers
32k 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 ...
user avatar
2 votes
3 answers
603 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 ...
user avatar
  • 1,731
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', ...
user avatar
  • 1,685
2 votes
2 answers
92 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 ...
user avatar
  • 299
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 ...
user avatar
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!
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 ...
user avatar
2 votes
2 answers
103 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 ...
user avatar
  • 99
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....
user avatar
  • 13.3k
2 votes
1 answer
655 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 ...
user avatar
  • 228
2 votes
1 answer
218 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 ...
user avatar
  • 1,828
2 votes
1 answer
97 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 ...
user avatar
  • 251
2 votes
2 answers
604 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 ...
user avatar
2 votes
2 answers
1k 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 ...
user avatar
  • 701
2 votes
1 answer
77 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 ...
user avatar
  • 23.6k
2 votes
1 answer
184 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....
user avatar
  • 23.6k
2 votes
1 answer
431 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 ...
user avatar
2 votes
2 answers
565 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, ...
user avatar
  • 41
2 votes
1 answer
153 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 ...
user avatar
2 votes
2 answers
13k 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 ...
user avatar
  • 21
2 votes
1 answer
615 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 ...
user avatar
2 votes
1 answer
215 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 ...
user avatar
  • 103
2 votes
1 answer
554 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 ...
user avatar
2 votes
1 answer
312 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 ...
user avatar
2 votes
1 answer
202 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 ...
user avatar
  • 13.3k
2 votes
0 answers
874 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 ...
user avatar
2 votes
0 answers
165 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 ...
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 ...
user avatar
  • 23.6k
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 ...
user avatar
1 vote
3 answers
55 views

How to use page specific javascript using asset rev plugin and webpack?

I have a similar question here. But I was NOT able to ask the right question. I'm practicing with starter-blog template. How do I use page specific javascript using the asset rev plugin and webpack? I ...
user avatar
  • 53
1 vote
2 answers
1k 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 ...
user avatar
1 vote
2 answers
401 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 ...
user avatar
  • 407