Docs for checkbox and radio
parent
624b67350d
commit
dfcd5e08e2
|
@ -21,7 +21,8 @@ export default {
|
|||
inputId: String,
|
||||
autofocus: Boolean,
|
||||
autocomplete: String,
|
||||
disabled: Boolean
|
||||
disabled: Boolean,
|
||||
binary: Boolean
|
||||
},
|
||||
model: {
|
||||
prop: 'modelValue',
|
||||
|
@ -37,15 +38,15 @@ export default {
|
|||
if (!this.disabled) {
|
||||
let newModelValue;
|
||||
|
||||
if (Array.isArray(this.modelValue)) {
|
||||
if (this.binary) {
|
||||
newModelValue = !this.modelValue;
|
||||
}
|
||||
else {
|
||||
if (this.checked)
|
||||
newModelValue = this.modelValue.filter(val => !ObjectUtils.equals(val, this.value));
|
||||
else
|
||||
newModelValue = this.modelValue ? [...this.modelValue, this.value] : [this.value];
|
||||
}
|
||||
else {
|
||||
newModelValue = !this.modelValue;
|
||||
}
|
||||
|
||||
this.$emit('click', event);
|
||||
this.$emit('input', newModelValue);
|
||||
|
@ -64,7 +65,7 @@ export default {
|
|||
},
|
||||
computed: {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ import Checkbox from 'primevue/checkbox';
|
|||
<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>
|
||||
<CodeHighlight>
|
||||
<Checkbox id="binary" inputId="binary" v-model="checked" />
|
||||
<Checkbox v-model="checked" :binary="true" />
|
||||
</CodeHighlight>
|
||||
|
||||
<h3>Multiple Values</h3>
|
||||
|
@ -32,22 +32,8 @@ export default {
|
|||
}
|
||||
</CodeHighlight>
|
||||
|
||||
|
||||
<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>
|
||||
<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>
|
||||
<div class="doc-tablewrapper">
|
||||
|
@ -95,13 +81,19 @@ export default {
|
|||
<td>autocomplete</td>
|
||||
<td>string</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>
|
||||
<td>autofocus</td>
|
||||
<td>boolean</td>
|
||||
<td>false</td>
|
||||
<td>When present, it specifies that the element should automatically get focus when the page loads.</td>
|
||||
</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>
|
||||
</table>
|
||||
|
|
|
@ -85,7 +85,7 @@ export default {
|
|||
<td>autocomplete</td>
|
||||
<td>string</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>
|
||||
</tbody>
|
||||
</table>
|
||||
|
|
|
@ -49,17 +49,17 @@ import TriStateCheckbox from 'primevue/tristatecheckbox';
|
|||
<td>false</td>
|
||||
<td>When present, it specifies that the element value cannot be altered.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>autocomplete</td>
|
||||
<td>string</td>
|
||||
<td>null</td>
|
||||
<td>When specifies, whether or not an the element should have autocomplete enabled.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>autofocus</td>
|
||||
<td>boolean</td>
|
||||
<td>false</td>
|
||||
<td>When present, it specifies that the element should automatically get focus when the page loads.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>autocomplete</td>
|
||||
<td>string</td>
|
||||
<td>null</td>
|
||||
<td>Whether an the element should have autocomplete enabled.</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
|
Loading…
Reference in New Issue