Docs for checkbox and radio

pull/12/head
cagataycivici 2019-05-22 18:54:46 +03:00
parent 624b67350d
commit dfcd5e08e2
4 changed files with 302 additions and 309 deletions

View File

@ -21,7 +21,8 @@ export default {
inputId: String, inputId: String,
autofocus: Boolean, autofocus: Boolean,
autocomplete: String, autocomplete: String,
disabled: Boolean disabled: Boolean,
binary: Boolean
}, },
model: { model: {
prop: 'modelValue', prop: 'modelValue',
@ -37,15 +38,15 @@ export default {
if (!this.disabled) { if (!this.disabled) {
let newModelValue; let newModelValue;
if (Array.isArray(this.modelValue)) { if (this.binary) {
newModelValue = !this.modelValue;
}
else {
if (this.checked) if (this.checked)
newModelValue = this.modelValue.filter(val => !ObjectUtils.equals(val, this.value)); newModelValue = this.modelValue.filter(val => !ObjectUtils.equals(val, this.value));
else else
newModelValue = this.modelValue ? [...this.modelValue, this.value] : [this.value]; newModelValue = this.modelValue ? [...this.modelValue, this.value] : [this.value];
} }
else {
newModelValue = !this.modelValue;
}
this.$emit('click', event); this.$emit('click', event);
this.$emit('input', newModelValue); this.$emit('input', newModelValue);
@ -64,7 +65,7 @@ export default {
}, },
computed: { computed: {
checked() { checked() {
return Array.isArray(this.modelValue) ? ObjectUtils.contains(this.value, this.modelValue) : this.modelValue; return this.binary ? this.modelValue : ObjectUtils.contains(this.value, this.modelValue);
} }
} }
} }

View File

@ -10,7 +10,7 @@ import Checkbox from 'primevue/checkbox';
<h3>Getting Started</h3> <h3>Getting Started</h3>
<p>Checkbox can either be used in multiple selection with other checkboxes or as a single checkbox to provide a boolean value.</p> <p>Checkbox can either be used in multiple selection with other checkboxes or as a single checkbox to provide a boolean value.</p>
<CodeHighlight> <CodeHighlight>
&lt;Checkbox id=&quot;binary&quot; inputId=&quot;binary&quot; v-model=&quot;checked&quot; /&gt; &lt;Checkbox v-model=&quot;checked&quot; :binary="true" /&gt;
</CodeHighlight> </CodeHighlight>
<h3>Multiple Values</h3> <h3>Multiple Values</h3>
@ -32,77 +32,69 @@ export default {
} }
</CodeHighlight> </CodeHighlight>
<p>As v-model is two-way binding enabled, prepopulating the model array with values is enough to display the related <p>As v-model is two-way binding enabled, prepopulating the model array with values is enough to display the related
checkboxes as checked by default.</p> checkboxes as checked by default.</p>
<CodeHighlight lang="js">
export default {
data() {
return {
themes: [{name: 'Apollo', key: 'A'}, {name: 'Babylon', key: 'B'}, {name: 'Serenity', key: 'S'}, {name: 'Ultima', key: 'U'}],
selectedThemes: []
}
},
created() {
this.selectedThemes = this.themes.slice(1,3);
}
}
</CodeHighlight>
<h3>Properties</h3> <h3>Properties</h3>
<div class="doc-tablewrapper"> <div class="doc-tablewrapper">
<table class="doc-table"> <table class="doc-table">
<thead> <thead>
<tr> <tr>
<th>Name</th> <th>Name</th>
<th>Type</th> <th>Type</th>
<th>Default</th> <th>Default</th>
<th>Description</th> <th>Description</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr> <tr>
<td>inputId</td> <td>inputId</td>
<td>string</td> <td>string</td>
<td>null</td> <td>null</td>
<td>Unique identifier of the inner native checkbox.</td> <td>Unique identifier of the inner native checkbox.</td>
</tr> </tr>
<tr> <tr>
<td>value</td> <td>value</td>
<td>any</td> <td>any</td>
<td>null</td> <td>null</td>
<td>Value of the checkbox.</td> <td>Value of the checkbox.</td>
</tr> </tr>
<tr> <tr>
<td>name</td> <td>name</td>
<td>string</td> <td>string</td>
<td>null</td> <td>null</td>
<td>Name of the checkbox element .</td> <td>Name of the checkbox element .</td>
</tr> </tr>
<tr> <tr>
<td>disabled</td> <td>disabled</td>
<td>boolean</td> <td>boolean</td>
<td>false</td> <td>false</td>
<td>When present, it specifies that the element value cannot be altered.</td> <td>When present, it specifies that the element value cannot be altered.</td>
</tr> </tr>
<tr> <tr>
<td>modelValue</td> <td>modelValue</td>
<td>any</td> <td>any</td>
<td>null</td> <td>null</td>
<td>Value of the checkbox.</td> <td>Value of the checkbox.</td>
</tr> </tr>
<tr> <tr>
<td>autocomplete</td> <td>autocomplete</td>
<td>string</td> <td>string</td>
<td>null</td> <td>null</td>
<td>When specifies, whether or not an the element should have autocomplete enabled.</td> <td>Whether an the element should have autocomplete enabled.</td>
</tr> </tr>
<tr> <tr>
<td>autofocus</td> <td>autofocus</td>
<td>boolean</td> <td>boolean</td>
<td>false</td> <td>false</td>
<td>When present, it specifies that the element should automatically get focus when the page loads.</td> <td>When present, it specifies that the element should automatically get focus when the page loads.</td>
</tr> </tr>
<tr>
<td>binary</td>
<td>boolean</td>
<td>false</td>
<td>Allows to select a boolean value instead of multiple values.</td>
</tr>
</tbody> </tbody>
</table> </table>
</div> </div>
@ -111,38 +103,38 @@ export default {
<div class="doc-tablewrapper"> <div class="doc-tablewrapper">
<table class="doc-table"> <table class="doc-table">
<thead> <thead>
<tr> <tr>
<th>Name</th> <th>Name</th>
<th>Parameters</th> <th>Parameters</th>
<th>Description</th> <th>Description</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr> <tr>
<td>change</td> <td>change</td>
<td>event: Browser event</td> <td>event: Browser event</td>
<td>Callback to invoke on value change.</td> <td>Callback to invoke on value change.</td>
</tr> </tr>
<tr> <tr>
<td>input</td> <td>input</td>
<td>event: Value of checkbox</td> <td>event: Value of checkbox</td>
<td>Callback to invoke on click.</td> <td>Callback to invoke on click.</td>
</tr> </tr>
<tr> <tr>
<td>click</td> <td>click</td>
<td>event: Browser event</td> <td>event: Browser event</td>
<td>Callback to invoke click.</td> <td>Callback to invoke click.</td>
</tr> </tr>
<tr> <tr>
<td>focus</td> <td>focus</td>
<td>event: Browser event</td> <td>event: Browser event</td>
<td>Callback to invoke on focus.</td> <td>Callback to invoke on focus.</td>
</tr> </tr>
<tr> <tr>
<td>blur</td> <td>blur</td>
<td>event: Browser event</td> <td>event: Browser event</td>
<td>Callback to invoke on blur.</td> <td>Callback to invoke on blur.</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
</div> </div>
@ -152,28 +144,28 @@ export default {
<div class="doc-tablewrapper"> <div class="doc-tablewrapper">
<table class="doc-table"> <table class="doc-table">
<thead> <thead>
<tr> <tr>
<th>Name</th> <th>Name</th>
<th>Element</th> <th>Element</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr> <tr>
<td>p-chkbox</td> <td>p-chkbox</td>
<td>Container element</td> <td>Container element</td>
</tr> </tr>
<tr> <tr>
<td>p-chkbox-box</td> <td>p-chkbox-box</td>
<td>Container of icon.</td> <td>Container of icon.</td>
</tr> </tr>
<tr> <tr>
<td>p-chkbox-icon</td> <td>p-chkbox-icon</td>
<td>Icon element.</td> <td>Icon element.</td>
</tr> </tr>
<tr> <tr>
<td>p-chkbox-label</td> <td>p-chkbox-label</td>
<td>Label element.</td> <td>Label element.</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
</div> </div>

View File

@ -37,56 +37,56 @@ export default {
<div class="doc-tablewrapper"> <div class="doc-tablewrapper">
<table class="doc-table"> <table class="doc-table">
<thead> <thead>
<tr> <tr>
<th>Name</th> <th>Name</th>
<th>Type</th> <th>Type</th>
<th>Default</th> <th>Default</th>
<th>Description</th> <th>Description</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr> <tr>
<td>inputId</td> <td>inputId</td>
<td>string</td> <td>string</td>
<td>null</td> <td>null</td>
<td>Unique identifier of the inner native radiobutton.</td> <td>Unique identifier of the inner native radiobutton.</td>
</tr> </tr>
<tr> <tr>
<td>name</td> <td>name</td>
<td>string</td> <td>string</td>
<td>null</td> <td>null</td>
<td>Name of the checkbox element .</td> <td>Name of the checkbox element .</td>
</tr> </tr>
<tr> <tr>
<td>value</td> <td>value</td>
<td>any</td> <td>any</td>
<td>null</td> <td>null</td>
<td>Value of the radiobutton.</td> <td>Value of the radiobutton.</td>
</tr> </tr>
<tr> <tr>
<td>disabled</td> <td>disabled</td>
<td>boolean</td> <td>boolean</td>
<td>false</td> <td>false</td>
<td>When present, it specifies that the element value cannot be altered.</td> <td>When present, it specifies that the element value cannot be altered.</td>
</tr> </tr>
<tr> <tr>
<td>modelValue</td> <td>modelValue</td>
<td>any</td> <td>any</td>
<td>null</td> <td>null</td>
<td>Value of the checkbox.</td> <td>Value of the checkbox.</td>
</tr> </tr>
<tr> <tr>
<td>autofocus</td> <td>autofocus</td>
<td>boolean</td> <td>boolean</td>
<td>null</td> <td>null</td>
<td>When present, it specifies that the element should automatically get focus when the page loads.</td> <td>When present, it specifies that the element should automatically get focus when the page loads.</td>
</tr> </tr>
<tr> <tr>
<td>autocomplete</td> <td>autocomplete</td>
<td>string</td> <td>string</td>
<td>null</td> <td>null</td>
<td>When specifies, whether or not an the element should have autocomplete enabled.</td> <td>Whether or not an the element should have autocomplete enabled.</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
</div> </div>
@ -95,38 +95,38 @@ export default {
<div class="doc-tablewrapper"> <div class="doc-tablewrapper">
<table class="doc-table"> <table class="doc-table">
<thead> <thead>
<tr> <tr>
<th>Name</th> <th>Name</th>
<th>Parameters</th> <th>Parameters</th>
<th>Description</th> <th>Description</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr> <tr>
<td>change</td> <td>change</td>
<td>event: Browser event</td> <td>event: Browser event</td>
<td>Callback to invoke on value change.</td> <td>Callback to invoke on value change.</td>
</tr> </tr>
<tr> <tr>
<td>input</td> <td>input</td>
<td>event: Value of checkbox</td> <td>event: Value of checkbox</td>
<td>Callback to invoke on click.</td> <td>Callback to invoke on click.</td>
</tr> </tr>
<tr> <tr>
<td>click</td> <td>click</td>
<td>event: Browser event</td> <td>event: Browser event</td>
<td>Callback to invoke click.</td> <td>Callback to invoke click.</td>
</tr> </tr>
<tr> <tr>
<td>focus</td> <td>focus</td>
<td>event: Browser event</td> <td>event: Browser event</td>
<td>Callback to invoke on focus.</td> <td>Callback to invoke on focus.</td>
</tr> </tr>
<tr> <tr>
<td>blur</td> <td>blur</td>
<td>event: Browser event</td> <td>event: Browser event</td>
<td>Callback to invoke on blur.</td> <td>Callback to invoke on blur.</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
</div> </div>
@ -136,28 +136,28 @@ export default {
<div class="doc-tablewrapper"> <div class="doc-tablewrapper">
<table class="doc-table"> <table class="doc-table">
<thead> <thead>
<tr> <tr>
<th>Name</th> <th>Name</th>
<th>Element</th> <th>Element</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr> <tr>
<td>p-radiobutton</td> <td>p-radiobutton</td>
<td>Container element</td> <td>Container element</td>
</tr> </tr>
<tr> <tr>
<td>p-radiobutton-box</td> <td>p-radiobutton-box</td>
<td>Container of icon.</td> <td>Container of icon.</td>
</tr> </tr>
<tr> <tr>
<td>p-radiobutton-icon</td> <td>p-radiobutton-icon</td>
<td>Icon element.</td> <td>Icon element.</td>
</tr> </tr>
<tr> <tr>
<td>p-radiobutton-label</td> <td>p-radiobutton-label</td>
<td>Label element.</td> <td>Label element.</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
</div> </div>

View File

@ -17,50 +17,50 @@ import TriStateCheckbox from 'primevue/tristatecheckbox';
<div class="doc-tablewrapper"> <div class="doc-tablewrapper">
<table class="doc-table"> <table class="doc-table">
<thead> <thead>
<tr> <tr>
<th>Name</th> <th>Name</th>
<th>Type</th> <th>Type</th>
<th>Default</th> <th>Default</th>
<th>Description</th> <th>Description</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr> <tr>
<td>inputId</td> <td>inputId</td>
<td>string</td> <td>string</td>
<td>null</td> <td>null</td>
<td>Unique identifier of the native checkbox element.</td> <td>Unique identifier of the native checkbox element.</td>
</tr> </tr>
<tr> <tr>
<td>value</td> <td>value</td>
<td>any</td> <td>any</td>
<td>null</td> <td>null</td>
<td>Value of the TriStateCheckbox.</td> <td>Value of the TriStateCheckbox.</td>
</tr> </tr>
<tr> <tr>
<td>name</td> <td>name</td>
<td>string</td> <td>string</td>
<td>null</td> <td>null</td>
<td>Name of the checkbox element .</td> <td>Name of the checkbox element .</td>
</tr> </tr>
<tr> <tr>
<td>disabled</td> <td>disabled</td>
<td>boolean</td> <td>boolean</td>
<td>false</td> <td>false</td>
<td>When present, it specifies that the element value cannot be altered.</td> <td>When present, it specifies that the element value cannot be altered.</td>
</tr> </tr>
<tr> <tr>
<td>autocomplete</td> <td>autofocus</td>
<td>string</td> <td>boolean</td>
<td>null</td> <td>false</td>
<td>When specifies, whether or not an the element should have autocomplete enabled.</td> <td>When present, it specifies that the element should automatically get focus when the page loads.</td>
</tr> </tr>
<tr> <tr>
<td>autofocus</td> <td>autocomplete</td>
<td>boolean</td> <td>string</td>
<td>false</td> <td>null</td>
<td>When present, it specifies that the element should automatically get focus when the page loads.</td> <td>Whether an the element should have autocomplete enabled.</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
</div> </div>
@ -69,38 +69,38 @@ import TriStateCheckbox from 'primevue/tristatecheckbox';
<div class="doc-tablewrapper"> <div class="doc-tablewrapper">
<table class="doc-table"> <table class="doc-table">
<thead> <thead>
<tr> <tr>
<th>Name</th> <th>Name</th>
<th>Parameters</th> <th>Parameters</th>
<th>Description</th> <th>Description</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr> <tr>
<td>change</td> <td>change</td>
<td>event: Browser event</td> <td>event: Browser event</td>
<td>Callback to invoke on value change.</td> <td>Callback to invoke on value change.</td>
</tr> </tr>
<tr> <tr>
<td>input</td> <td>input</td>
<td>event: Value of checkbox</td> <td>event: Value of checkbox</td>
<td>Callback to invoke on click.</td> <td>Callback to invoke on click.</td>
</tr> </tr>
<tr> <tr>
<td>click</td> <td>click</td>
<td>event: Browser event</td> <td>event: Browser event</td>
<td>Callback to invoke click.</td> <td>Callback to invoke click.</td>
</tr> </tr>
<tr> <tr>
<td>focus</td> <td>focus</td>
<td>event: Browser event</td> <td>event: Browser event</td>
<td>Callback to invoke on focus.</td> <td>Callback to invoke on focus.</td>
</tr> </tr>
<tr> <tr>
<td>blur</td> <td>blur</td>
<td>event: Browser event</td> <td>event: Browser event</td>
<td>Callback to invoke on blur.</td> <td>Callback to invoke on blur.</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
</div> </div>
@ -110,28 +110,28 @@ import TriStateCheckbox from 'primevue/tristatecheckbox';
<div class="doc-tablewrapper"> <div class="doc-tablewrapper">
<table class="doc-table"> <table class="doc-table">
<thead> <thead>
<tr> <tr>
<th>Name</th> <th>Name</th>
<th>Element</th> <th>Element</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr> <tr>
<td>p-chkbox</td> <td>p-chkbox</td>
<td>Container element</td> <td>Container element</td>
</tr> </tr>
<tr> <tr>
<td>p-tristatechkbox</td> <td>p-tristatechkbox</td>
<td>Container element</td> <td>Container element</td>
</tr> </tr>
<tr> <tr>
<td>p-chkbox-box</td> <td>p-chkbox-box</td>
<td>Container of icon.</td> <td>Container of icon.</td>
</tr> </tr>
<tr> <tr>
<td>p-chkbox-icon</td> <td>p-chkbox-icon</td>
<td>Icon element.</td> <td>Icon element.</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
</div> </div>