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,22 +32,8 @@ 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">
@ -95,13 +81,19 @@ export default {
<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>
<td>binary</td>
<td>boolean</td>
<td>false</td>
<td>Allows to select a boolean value instead of multiple values.</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>

View File

@ -85,7 +85,7 @@ export default {
<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>

View File

@ -49,17 +49,17 @@ import TriStateCheckbox from 'primevue/tristatecheckbox';
<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>
<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> <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>
<td>autocomplete</td>
<td>string</td>
<td>null</td>
<td>Whether an the element should have autocomplete enabled.</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>