Add-ons / Disable Macro

The <<disable>> macro allows the user to disable (and re-enable) various interactive elements.

Author ChapelR
Website https://twinelab.net/custom-macros-for-sugarcube-2/#/disable-macro
Story format SugarCube 2
Last checked Sat Nov 14 2020
License Unlicense
Download disable.zip

Index

Overview

The <<disable>> macro allows the user to disable (and re-enable) various interactive elements.

Macros

<<disable>>

<<disable>>

Syntax: <<disable [expression]>>...<</disable>>

The first interactive element (such as a button or text input) between the macro tags will be disabled. If an expression is passed to the macro, it will be evaluated. If the evaluated expression yields a truthy result, the interactive element will be disabled. If the expression is falsy, the element will not be disabled.

Usage:

This button should be disabled:
<<disable>><<button "Submit">><</button>><</disable>>

This textbox should also be disabled:
<<disable 1 === 1>><<textbox "$name" "">><</disable>>

This listbox, too:
<<disable true>><<listbox '$whee'>><<optionsfrom ["1", "2", "3"]>><</listbox>><</disable>>

This button should ''not'' be disabled:
<<disable false>><<button "Submit">><</button>><</disable>>

This textbox should ''not'' be disabled:
<<disable 1 === 0>><<textbox "$name" "">><</disable>>

READ: Documentation

Usage notes

Disabled elements are also given the class disabled.

Live demo

Demo Twee code:

:: Start
This button should be disabled: <<disable>><<button "Submit">><</button>><</disable>>