- concrete5 Cookbook
- David Strack
- 191字
- 2021-08-13 16:16:01
Including JavaScript in block forms
When adding or editing blocks, it is often desired to include more advanced functionality in the form of client-side JavaScript. concrete5 makes it extremely easy to automatically add a JavaScript file to a block's editor form.
Getting ready
We will be working with the block that was created in the first recipe of this chapter. If you need to catch up, feel free to download the code from this book's website.
How to do it...
The steps for including JavaScript in block forms are as follows:
- Open your block's directory.
- Create a new file called
auto.js
. - Add a basic alert function to
auto.js
:alert('Hello!');
- Visit a page that contains your block.
- Enter edit mode and edit the block.
- You should see your alert message appear as shown in the following screenshot:
How it works...
concrete5 automatically looks for the auto.js
file when it enters add or edit mode on a block. Developers can use this to their advantage to contain special client-side functionality for the block's edit mode.
See also
- The Including JavaScript in the block view recipe
- The Including CSS in the block view recipe
推薦閱讀
- Git高手之路
- 用Flutter極速構(gòu)建原生應(yīng)用
- Scala編程實戰(zhàn)(原書第2版)
- 數(shù)據(jù)結(jié)構(gòu)與算法分析(C++語言版)
- Mastering Android Game Development
- Learning Apache Cassandra
- Mastering Backbone.js
- Oracle數(shù)據(jù)庫編程經(jīng)典300例
- Building Dynamics CRM 2015 Dashboards with Power BI
- 深度探索Go語言:對象模型與runtime的原理特性及應(yīng)用
- 精通Spring:Java Web開發(fā)與Spring Boot高級功能
- Kotlin進(jìn)階實戰(zhàn)
- Modular Programming with JavaScript
- C# 7.0本質(zhì)論
- HTML5 WebSocket權(quán)威指南