Handle Conditional Elements jQuery dataDisplay - Download Handling Conditional Elements Based On User Input - jQuery dataDisplay.js

Download Handling Conditional Elements Based On User Input – jQuery dataDisplay.js

Posted on

This time I will share jQuery Plugin and tutorial about Handling Conditional Elements Based On User Input – jQuery dataDisplay.js, hope it will help you in programming stack.

Handle Conditional Elements jQuery dataDisplay - Download Handling Conditional Elements Based On User Input - jQuery dataDisplay.js

File Size: 652 KB
Views Total: 790
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   

dataDisplay.js is a jQuery plugin for handling conditional elements that allows to control the display of DOM elements based on user input.

Basic usage:

1. Include the jQuery dataDisplay.js after loading jQuery library.

1 <script src="//code.jquery.com/jquery.min.js"></script>
2 <script src="jquery.dataDisplay.min.js"></script>

2. Initialize the plugin on the target container.

1 $('#container').dataDisplay();

3. Define the conditions in the ‘data-display’ attribute as these:

01 <div id="container">
02   <label for="yes">
03       <input type="radio" name="radioTest" value="yes" id="yes" checked/> Yes</label>
04   <label for="no">
05       <input type="radio" name="radioTest" value="no" id="no"/> No</label>
06   <b>Type "testing":</b>
07   <input name="inputTest" type="value"/>
08   <div class="dataDisplay"
09       data-display="
10           {radioTest} == 'yes' && (length({inputTest}) is less than or equal to 6); ||
11           {radioTest} == 'yes' && ({inputTest} is equal to 'testing' || {inputTest} is equal to 'testinggg'); ||
12           {inputTest} is equal to 'testing' || {inputTest}=='testinggg' :: $this.css('background','black'); ||
13           {inputTest} is equal to 'testing' :: $this.css('color','white');$this.css('font-size','20px');$this.css('border','1px solid #fff'); ||
14           {inputTest} is equal to 'testinggg' :: $this.css('color','yellow');$this.css('border','1px solid yellow');"
15       data-display-resets="
16           $this.css('color', 'black');
17           $this.css('font-size', '16px');
18           $this.css('background', '#fff');
19           $this.css('border', '1px solid #000');">
20       <a>type 'testing' or 'testinggg' in the field above</a>
21       <a>(box will hide when length > 6 when value !== testing or testinggg)</a>
22   </div>
23   <div class="dataDisplay"
24       data-display="
25           {radioTest} == 'no';">
26       <a>select the 'yes' radio field above</a>
27   </div>
28 </div>

4. Helper methods included:

1 data-display="{input} == "value";"
2 data-display="!empty({input});"
3 data-display="empty({input});"
4 data-display="length({input}) > 10;"
5 data-display="{input} is greater than or equal to 10;"
6 data-display="{input} is less than or equal to 10;"
7 data-display="{input} is greater than 10;"
8 data-display="{input} is less than 10;"
9 data-display="{input} is equal to 10;"

5. Default plugin options:

1 $('#container').dataDisplay({
2   eventName: ".dataDisplay",
3   dataAttr: "dataDisplay",
4   condsAttr: "data-display",
5   resetsAttr: "data-display-resets",
6   initFire: true,
7   keyEventsFire: ture, // recheck conditions on keyup
8   funcs: {}, // for custom helper methods
9 });

This awesome jQuery plugin is developed by assetinfo. For more Advanced Usages, please check the demo page or visit the official website.

source : jqueryscript.net