Javascript component that shows and hides page elements based on form field values
Download View on GithubThis plugin requires jQuery. In the HTML page, first include jQuery, then Conditional Field. Be sure to place the script tags just before the closing body tag.
Example:
...
...
The script tags can also be placed in the head tag. If doing so, all calls to Conditional Field must be wrapped in a $(document).ready()
block.
Example:
$(document).ready(function(){
new ConditionalField({
...
});
});
Run bower install --save conditional-field
, then reference the files in the HTML page.
Run npm install --save conditional-field
, then reference the files in the HTML page.
Download conditional-field.min.js and place it in your project directory. Then reference the files in the HTML page.
new ConditionalField({
control: '.select-field',
visibility: {
'credit': '.credit',
'check': '.check'
}
});
new ConditionalField({
control: '.payment-radios',
visibility: {
'credit': '.credit',
'check': '.check'
}
});
new ConditionalField({
control: '.payment-checkbox',
visibility: {
'off': '.credit',
'on': '.check'
}
});
Name | Type | Description |
---|---|---|
control |
string (element selector) | Form element used to determine visibility of connected elements. The value of this element will be used to find the matching value in the visibility option. |
visibility |
JSON object |
The keys provided in this object are used to match the value of the
|