Questions tagged [javascript]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
2 votes
1 answer
345 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
1 vote
1 answer
504 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'...
Robin Schambach's user avatar
1 vote
1 answer
901 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 ...
user2190590's user avatar
2 votes
1 answer
270 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.4k
1 vote
1 answer
77 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 ...
Retroity's user avatar
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,695
2 votes
1 answer
166 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
1 vote
1 answer
70 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 ...
Ben Parizek's user avatar
  • 13.4k
1 vote
0 answers
841 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 ...
samput's user avatar
  • 51
0 votes
1 answer
317 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 ...
Robbie Post's user avatar
1 vote
2 answers
576 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 ...
Jai Sandhu's user avatar
2 votes
1 answer
4k 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
1 vote
2 answers
2k 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 ...
abhim12's user avatar
  • 33
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
1 vote
2 answers
172 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 ...
CreateSean's user avatar
  • 1,963
1 vote
1 answer
3k 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 ...
mierla's user avatar
  • 43
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
  • 921
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
  • 731
1 vote
1 answer
345 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 ...
user3285578's user avatar
2 votes
1 answer
691 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
1 vote
0 answers
172 views

Need help with filtering entries by a custom field using ajax with pagination

I'm fairly new to CraftCMS and am stuck with a little filtering issue. I'm trying to filter a page of entries by a custom field. I'd like to use Ajax so there is no page reload. Here's how I have the ...
Rich Bachman's user avatar
1 vote
1 answer
3k views

Can a JS string variable be used in Twig?

I've came to the situation where I need to use JS variable string and use it in Twig's variable. The plan is built on the Guest entries and Ajax form submission. On successful Ajax form submission I'...
Dominik Krulak's user avatar
1 vote
0 answers
542 views

Craft Nginx Cache Static Resources - Css, JS Errors

I'm currently trying to cache css and js files with the widely known config as follows: location ~* \.(png|jpg|css|js|jpeg|gif|ico|xls|doc|zip|exe|mp3|mp4|pdf|ai|psd|eps|ppt|dmg|csv|key|numbers|cur|...
Adam I's user avatar
  • 11
2 votes
1 answer
244 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
1 vote
0 answers
613 views

CSRF token creation and Content-Security-Policy header

I've just updated my site with setting my Content-Security-Policy Header and after fixing the slew of errors which popped up in the console, I am now down to one. The relevant part of my .htaccess ...
rjdvsk's user avatar
  • 105
1 vote
1 answer
725 views

How to replace a html entity within script tags using Craft replace

Apologies if this has been asked before, I can only find questions dealing with the reverse scenario (i.e. replacing special characters with html entities) I need to output special characters as part ...
S. Connolly22's user avatar
0 votes
1 answer
913 views

Link Popup Modal to correct script in loop

Popup Closed Screenshot Popup Open Screenshot I have image that has multiple markers on it that can be clicked to bring up different popups. However, I need to some help refining the code to work ...
mention79's user avatar
  • 543
1 vote
1 answer
704 views

SearchPlus plugin configuration

How can you change from instant search and faceting to a search bar with auto-completion? SearchPlus comes with an excellent sample template but this is set to instant search, which means all entries ...
Nutmeg's user avatar
  • 598
1 vote
1 answer
89 views

Javascript issue when setting an expiry date for entry

If I set an expiry date for an entry I get an error on one of the last lines: $timePicker.timepicker('setTime', Name of edit section as shown to the user*3600 + 00*60 + 00); I've traced this back to ...
KnutSv's user avatar
  • 268
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
1 vote
1 answer
1k 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 ...
Hellyar's user avatar
  • 921
5 votes
1 answer
3k 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,128
1 vote
1 answer
248 views

HTML and Scripts in Entries?

I am building a section in which a client will list their various social network connections. There are fields for each social network's name and icon, as well as a field with the URL to the client's ...
Philip Jones's user avatar
0 votes
1 answer
493 views

Craft and AJAX page transitions - how to exclude local hash links from executing AJAX? [closed]

I've got a website in development with new pages loaded via AJAX instead of traditional page loads. Most links on the site will use AJAX to load a new page, however there are some links I need to ...
Benek Lisefski's user avatar
1 vote
1 answer
1k views

Ajax Function on a search form not working in Safari & IE

I made an ajax function so my page wont refresh and my search window wont disappear on form submit. It works fine in all browsers but it keeps refreshing on Safari. Here is my code: {% if not craft....
Justin Dekkers's user avatar
1 vote
1 answer
1k views

I want to get the HTML/text contents of the Redactor editor

I'm building a plugin for Craft CMS. This plugin will load on the edit/content page, where the standard Redactor WYSIWYG editor will be loaded too (by CraftCMS). I want to get the HTML/text contents ...
iNalgiev's user avatar
2 votes
0 answers
935 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
1 vote
1 answer
152 views

How to watch for changes on an Element Select Relations field?

I have a situation where I'd like to watch for a change in an Element Select field and determine if any Elements have been selected or not. Element Select fields have two input elements. One, is ...
Ben Parizek's user avatar
  • 13.4k
2 votes
0 answers
167 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
3 answers
655 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
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
  • 2,014
3 votes
1 answer
319 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
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.4k
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
3 votes
1 answer
187 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
1 answer
85 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
  • 24k
1 vote
1 answer
174 views

Element API - UrlHelper generates backwards slashes (regex)

I am generating a url within Element API: 'profile' => UrlHelper::getUrl("directory/company/{$member->id}/{$urlslug}"), which outputs: http:\/\/craft.fira\/directory\/company\/1501\/abet-...
Adam Menczykowski'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
209 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
  • 24k
1 vote
1 answer
654 views

minify javascript with includeJS

If i include javascript in a template using: {% set myJS %} //some JS in here {% endset %} {% includeJS myJS %} Is there a way to minify the javascript that gets output on the page? I had a look at ...
alexr's user avatar
  • 608