2020-12-07 14:36:46 +00:00
|
|
|
<template>
|
2021-04-06 09:16:59 +00:00
|
|
|
<AppDoc name="CascadeSelectDemo" :sources="sources" github="cascadeselect/CascadeSelectDemo.vue">
|
2021-10-22 10:23:03 +00:00
|
|
|
<h5>Import via Module</h5>
|
2021-02-03 10:10:30 +00:00
|
|
|
<pre v-code.script><code>
|
2020-12-07 14:36:46 +00:00
|
|
|
import CascadeSelect from 'primevue/cascadeselect';
|
|
|
|
|
2021-10-13 14:35:09 +00:00
|
|
|
</code></pre>
|
|
|
|
|
|
|
|
<h5>Import via CDN</h5>
|
|
|
|
<pre v-code><code>
|
2021-10-26 08:41:57 +00:00
|
|
|
<script src="https://unpkg.com/primevue@^3/core/core.min.js"></script>
|
2021-10-13 14:35:09 +00:00
|
|
|
<script src="https://unpkg.com/primevue@^3/cascadeselect/cascadeselect.min.js"></script>
|
|
|
|
|
2020-12-07 14:36:46 +00:00
|
|
|
</code></pre>
|
|
|
|
|
2021-03-18 10:41:31 +00:00
|
|
|
<h5>Getting Started</h5>
|
|
|
|
<p>CascadeSelect requires a value to bind and a collection of arbitrary objects with a nested hierarchy. <i>optionGroupLabel</i>
|
|
|
|
is used for the text of a category and <i>optionGroupChildren</i> is to define the children of the category. Note that order of the <i>optionGroupChildren</i>
|
|
|
|
matters and it should correspond to the data hierarchy.</p>
|
2020-12-07 14:36:46 +00:00
|
|
|
|
2021-02-03 10:10:30 +00:00
|
|
|
<pre v-code><code>
|
2020-12-07 14:36:46 +00:00
|
|
|
<CascadeSelect v-model="selectedCity" :options="countries" optionLabel="cname" optionGroupLabel="name"
|
|
|
|
:optionGroupChildren="['states', 'cities']" style="minWidth: 14rem" >
|
|
|
|
|
|
|
|
</code></pre>
|
|
|
|
|
2021-02-03 10:10:30 +00:00
|
|
|
<pre v-code.script><code>
|
2020-12-07 14:36:46 +00:00
|
|
|
data() {
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
selectedCity: null,
|
|
|
|
countries: [
|
|
|
|
{
|
|
|
|
name: 'Australia',
|
|
|
|
code: 'AU',
|
|
|
|
states: [
|
|
|
|
{
|
|
|
|
name: 'New South Wales',
|
|
|
|
cities: [
|
|
|
|
{cname: 'Sydney', code: 'A-SY'},
|
|
|
|
{cname: 'Newcastle', code: 'A-NE'},
|
|
|
|
{cname: 'Wollongong', code: 'A-WO'}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Queensland',
|
|
|
|
cities: [
|
|
|
|
{cname: 'Brisbane', code: 'A-BR'},
|
|
|
|
{cname: 'Townsville', code: 'A-TO'}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Canada',
|
|
|
|
code: 'CA',
|
|
|
|
states: [
|
|
|
|
{
|
|
|
|
name: 'Quebec',
|
|
|
|
cities: [
|
|
|
|
{cname: 'Montreal', code: 'C-MO'},
|
|
|
|
{cname: 'Quebec City', code: 'C-QU'}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Ontario',
|
|
|
|
cities: [
|
|
|
|
{cname: 'Ottawa', code: 'C-OT'},
|
|
|
|
{cname: 'Toronto', code: 'C-TO'}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'United States',
|
|
|
|
code: 'US',
|
|
|
|
states: [
|
|
|
|
{
|
|
|
|
name: 'California',
|
|
|
|
cities: [
|
|
|
|
{cname: 'Los Angeles', code: 'US-LA'},
|
|
|
|
{cname: 'San Diego', code: 'US-SD'},
|
|
|
|
{cname: 'San Francisco', code: 'US-SF'}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Florida',
|
|
|
|
cities: [
|
|
|
|
{cname: 'Jacksonville', code: 'US-JA'},
|
|
|
|
{cname: 'Miami', code: 'US-MI'},
|
|
|
|
{cname: 'Tampa', code: 'US-TA'},
|
|
|
|
{cname: 'Orlando', code: 'US-OR'}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Texas',
|
|
|
|
cities: [
|
|
|
|
{cname: 'Austin', code: 'US-AU'},
|
|
|
|
{cname: 'Dallas', code: 'US-DA'},
|
|
|
|
{cname: 'Houston', code: 'US-HO'}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
</code></pre>
|
|
|
|
|
2021-03-18 10:41:31 +00:00
|
|
|
<h5>Templating</h5>
|
|
|
|
<p>Content of an item can be customized with the <i>option</i> template.</p>
|
2020-12-07 14:36:46 +00:00
|
|
|
|
2021-02-03 10:10:30 +00:00
|
|
|
<pre v-code><code><template v-pre>
|
2020-12-07 14:36:46 +00:00
|
|
|
<CascadeSelect v-model="selectedCity" :options="countries" optionLabel="cname" optionGroupLabel="name"
|
|
|
|
:optionGroupChildren="['states', 'cities']" style="minWidth: 14rem">
|
|
|
|
<template #option="slotProps">
|
|
|
|
<div class="country-item">
|
|
|
|
<img src="../../assets/images/flag_placeholder.png" :class="'flag flag-' + slotProps.option.code.toLowerCase()" v-if="slotProps.option.states" />
|
|
|
|
<i class="pi pi-compass p-mr-2" v-if="slotProps.option.cities"></i>
|
|
|
|
<i class="pi pi-map-marker p-mr-2" v-if="slotProps.option.cname"></i>
|
|
|
|
<span>{{slotProps.option.cname || slotProps.option.name}}</span>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
</CascadeSelect>
|
|
|
|
</template>
|
|
|
|
</code></pre>
|
|
|
|
|
|
|
|
<h5>Properties</h5>
|
2021-03-18 10:41:31 +00:00
|
|
|
<p>Any property as style and class are passed to the main container element. Following are the additional properties to configure the component.</p>
|
|
|
|
<div class="doc-tablewrapper">
|
|
|
|
<table class="doc-table">
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th>Name</th>
|
|
|
|
<th>Type</th>
|
|
|
|
<th>Default</th>
|
|
|
|
<th>Description</th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
<tr>
|
|
|
|
<td>modelValue</td>
|
|
|
|
<td>any</td>
|
|
|
|
<td>null</td>
|
|
|
|
<td>Value of the component.</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>options</td>
|
|
|
|
<td>array</td>
|
|
|
|
<td>null</td>
|
|
|
|
<td>An array of selectitems to display as the available options.</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>optionLabel</td>
|
2021-12-07 06:21:20 +00:00
|
|
|
<td>string | function</td>
|
2021-03-18 10:41:31 +00:00
|
|
|
<td>null</td>
|
|
|
|
<td>Property name or getter function to use as the label of an option.</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>optionValue</td>
|
2021-12-07 06:21:20 +00:00
|
|
|
<td>string | function</td>
|
2021-03-18 10:41:31 +00:00
|
|
|
<td>null</td>
|
|
|
|
<td>Property name or getter function to use as the value of an option, defaults to the option itself when not defined.</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>optionGroupLabel</td>
|
2021-12-07 06:21:20 +00:00
|
|
|
<td>string | function</td>
|
2021-03-18 10:41:31 +00:00
|
|
|
<td>null</td>
|
|
|
|
<td>Property name or getter function to use as the label of an option group.</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>optionGroupChildren</td>
|
2021-12-07 06:21:20 +00:00
|
|
|
<td>array | function</td>
|
2021-03-18 10:41:31 +00:00
|
|
|
<td>null</td>
|
|
|
|
<td>Property name or getter function to retrieve the items of a group.</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>placeholder</td>
|
|
|
|
<td>string</td>
|
|
|
|
<td>null</td>
|
|
|
|
<td>Default text to display when no option is selected.</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>disabled</td>
|
|
|
|
<td>boolean</td>
|
|
|
|
<td>false</td>
|
|
|
|
<td>When present, it specifies that the component should be disabled.</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>dataKey</td>
|
|
|
|
<td>string</td>
|
|
|
|
<td>null</td>
|
|
|
|
<td>A property to uniquely identify an option.</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>tabindex</td>
|
|
|
|
<td>number</td>
|
|
|
|
<td>null</td>
|
|
|
|
<td>Index of the element in tabbing order.</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>inputId</td>
|
|
|
|
<td>string</td>
|
|
|
|
<td>null</td>
|
|
|
|
<td>Identifier of the underlying input element.</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>ariaLabelledBy</td>
|
|
|
|
<td>string</td>
|
|
|
|
<td>null</td>
|
|
|
|
<td>Establishes relationships between the component and label(s) where its value should be one or more element IDs.</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>appendTo</td>
|
|
|
|
<td>string</td>
|
|
|
|
<td>body</td>
|
2021-04-16 09:17:19 +00:00
|
|
|
<td>A valid query selector or an HTMLElement to specify where the overlay gets attached. Special keywords are "body" for document body
|
|
|
|
and "self" for the element itself.</td>
|
2021-04-15 12:06:20 +00:00
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>panelClass</td>
|
|
|
|
<td>string</td>
|
|
|
|
<td>null</td>
|
|
|
|
<td>Style class of the overlay panel.</td>
|
2021-05-14 09:01:25 +00:00
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>loading</td>
|
|
|
|
<td>boolean</td>
|
|
|
|
<td>false</td>
|
|
|
|
<td>Whether the dropdown is in loading state.</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>loadingIcon</td>
|
|
|
|
<td>string</td>
|
|
|
|
<td>pi pi-spinner pi-spin</td>
|
|
|
|
<td>Icon to display in loading state.</td>
|
2021-03-18 10:41:31 +00:00
|
|
|
</tr>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</div>
|
2020-12-07 14:36:46 +00:00
|
|
|
|
2021-03-18 10:41:31 +00:00
|
|
|
<h5>Events</h5>
|
|
|
|
<div class="doc-tablewrapper">
|
|
|
|
<table class="doc-table">
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th>Name</th>
|
|
|
|
<th>Parameters</th>
|
|
|
|
<th>Description</th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
<tr>
|
|
|
|
<td>change</td>
|
|
|
|
<td>event.originalEvent: Original event <br />
|
|
|
|
event.value: Selected option value </td>
|
|
|
|
<td>Callback to invoke on value change.</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>group-change</td>
|
|
|
|
<td>event.originalEvent: Original event <br />
|
|
|
|
event.value: Selected option group </td>
|
|
|
|
<td>Callback to invoke when a group changes.</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>before-show</td>
|
|
|
|
<td>-</td>
|
|
|
|
<td>Callback to invoke before the overlay is shown.</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>before-hide</td>
|
|
|
|
<td>-</td>
|
|
|
|
<td>Callback to invoke before the overlay is hidden.</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>show</td>
|
|
|
|
<td>-</td>
|
|
|
|
<td>Callback to invoke when the overlay is shown.</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>hide</td>
|
|
|
|
<td>-</td>
|
|
|
|
<td>Callback to invoke when the overlay is hidden.</td>
|
|
|
|
</tr>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</div>
|
2020-12-07 14:36:46 +00:00
|
|
|
|
2021-03-18 10:41:31 +00:00
|
|
|
<h5>Slots</h5>
|
|
|
|
<div class="doc-tablewrapper">
|
|
|
|
<table class="doc-table">
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th>Name</th>
|
|
|
|
<th>Parameters</th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
<tr>
|
|
|
|
<td>value</td>
|
|
|
|
<td>value: Value of the component <br />
|
|
|
|
placeholder: Placeholder text to show</td>
|
2021-05-06 14:44:09 +00:00
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>option</td>
|
|
|
|
<td>option: Option instance</td>
|
2021-08-27 13:58:51 +00:00
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>indicator</td>
|
|
|
|
<td>-</td>
|
2021-03-18 10:41:31 +00:00
|
|
|
</tr>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</div>
|
2020-12-07 14:36:46 +00:00
|
|
|
|
2021-03-18 10:41:31 +00:00
|
|
|
<h5>Styling</h5>
|
|
|
|
<p>Following is the list of structural style classes, for theming classes visit <router-link to="/theming">theming</router-link> page.</p>
|
|
|
|
<div class="doc-tablewrapper">
|
|
|
|
<table class="doc-table">
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th>Name</th>
|
|
|
|
<th>Element</th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
<tr>
|
|
|
|
<td>p-cascadeselect</td>
|
|
|
|
<td>Container element.</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>p-cascadeselect-label</td>
|
|
|
|
<td>Element to display label of selected option.</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>p-cascadeselect-trigger</td>
|
|
|
|
<td>Icon element.</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>p-cascadeselect-panel</td>
|
|
|
|
<td>Icon element.</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>p-cascadeselect-items-wrapper</td>
|
|
|
|
<td>Wrapper element of items list.</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>p-cascadeselect-items</td>
|
|
|
|
<td>List element of items.</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>p-cascadeselect-item</td>
|
|
|
|
<td>An item in the list.</td>
|
|
|
|
</tr>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</div>
|
2020-12-07 14:36:46 +00:00
|
|
|
|
2021-03-18 10:41:31 +00:00
|
|
|
<h5>Dependencies</h5>
|
|
|
|
<p>None.</p>
|
|
|
|
</AppDoc>
|
2021-01-21 08:40:52 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
sources: {
|
2021-03-18 10:41:31 +00:00
|
|
|
'options-api': {
|
2021-04-05 09:29:28 +00:00
|
|
|
tabName: 'Options API Source',
|
2021-03-18 10:41:31 +00:00
|
|
|
content: `
|
|
|
|
<template>
|
|
|
|
<div>
|
2021-03-24 17:37:09 +00:00
|
|
|
<h5>Basic</h5>
|
|
|
|
<CascadeSelect v-model="selectedCity1" :options="countries" optionLabel="cname" optionGroupLabel="name"
|
|
|
|
:optionGroupChildren="['states', 'cities']" style="minWidth: 14rem" placeholder="Select a City" />
|
2021-01-21 08:40:52 +00:00
|
|
|
|
2021-03-24 17:37:09 +00:00
|
|
|
<h5>Templating</h5>
|
|
|
|
<CascadeSelect v-model="selectedCity2" :options="countries" optionLabel="cname" optionGroupLabel="name"
|
|
|
|
:optionGroupChildren="['states', 'cities']" style="minWidth: 14rem" placeholder="Select a City">
|
|
|
|
<template #option="slotProps">
|
|
|
|
<div class="country-item">
|
|
|
|
<img src="https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png" v-if="slotProps.option.states" />
|
|
|
|
<i class="pi pi-compass p-mr-2" v-if="slotProps.option.cities"></i>
|
|
|
|
<i class="pi pi-map-marker p-mr-2" v-if="slotProps.option.cname"></i>
|
|
|
|
<span>{{slotProps.option.cname || slotProps.option.name}}</span>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
</CascadeSelect>
|
2021-05-14 09:01:25 +00:00
|
|
|
|
|
|
|
<h5>Loading State</h5>
|
|
|
|
<CascadeSelect placeholder="Loading..." loading style="minWidth: 14rem"></CascadeSelect>
|
2021-01-21 08:40:52 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
selectedCity1: null,
|
|
|
|
selectedCity2: null,
|
|
|
|
countries: [
|
|
|
|
{
|
|
|
|
name: 'Australia',
|
|
|
|
code: 'AU',
|
|
|
|
states: [
|
|
|
|
{
|
|
|
|
name: 'New South Wales',
|
|
|
|
cities: [
|
|
|
|
{cname: 'Sydney', code: 'A-SY'},
|
|
|
|
{cname: 'Newcastle', code: 'A-NE'},
|
|
|
|
{cname: 'Wollongong', code: 'A-WO'}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Queensland',
|
|
|
|
cities: [
|
|
|
|
{cname: 'Brisbane', code: 'A-BR'},
|
|
|
|
{cname: 'Townsville', code: 'A-TO'}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Canada',
|
|
|
|
code: 'CA',
|
|
|
|
states: [
|
|
|
|
{
|
|
|
|
name: 'Quebec',
|
|
|
|
cities: [
|
|
|
|
{cname: 'Montreal', code: 'C-MO'},
|
|
|
|
{cname: 'Quebec City', code: 'C-QU'}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Ontario',
|
|
|
|
cities: [
|
|
|
|
{cname: 'Ottawa', code: 'C-OT'},
|
|
|
|
{cname: 'Toronto', code: 'C-TO'}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'United States',
|
|
|
|
code: 'US',
|
|
|
|
states: [
|
|
|
|
{
|
|
|
|
name: 'California',
|
|
|
|
cities: [
|
|
|
|
{cname: 'Los Angeles', code: 'US-LA'},
|
|
|
|
{cname: 'San Diego', code: 'US-SD'},
|
|
|
|
{cname: 'San Francisco', code: 'US-SF'}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Florida',
|
|
|
|
cities: [
|
|
|
|
{cname: 'Jacksonville', code: 'US-JA'},
|
|
|
|
{cname: 'Miami', code: 'US-MI'},
|
|
|
|
{cname: 'Tampa', code: 'US-TA'},
|
|
|
|
{cname: 'Orlando', code: 'US-OR'}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Texas',
|
|
|
|
cities: [
|
|
|
|
{cname: 'Austin', code: 'US-AU'},
|
|
|
|
{cname: 'Dallas', code: 'US-DA'},
|
|
|
|
{cname: 'Houston', code: 'US-HO'}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
2021-03-18 10:41:31 +00:00
|
|
|
}
|
|
|
|
<\\/script>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
img {
|
|
|
|
width: 18px;
|
|
|
|
margin-right: 0.5rem;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
`
|
|
|
|
},
|
|
|
|
'composition-api': {
|
2021-04-05 09:29:28 +00:00
|
|
|
tabName: 'Composition API Source',
|
2021-03-18 10:41:31 +00:00
|
|
|
content: `
|
|
|
|
<template>
|
|
|
|
<div>
|
2021-03-24 17:37:09 +00:00
|
|
|
<h5>Basic</h5>
|
|
|
|
<CascadeSelect v-model="selectedCity1" :options="countries" optionLabel="cname" optionGroupLabel="name"
|
|
|
|
:optionGroupChildren="['states', 'cities']" style="minWidth: 14rem" placeholder="Select a City" />
|
2021-03-18 10:41:31 +00:00
|
|
|
|
2021-03-24 17:37:09 +00:00
|
|
|
<h5>Templating</h5>
|
|
|
|
<CascadeSelect v-model="selectedCity2" :options="countries" optionLabel="cname" optionGroupLabel="name"
|
|
|
|
:optionGroupChildren="['states', 'cities']" style="minWidth: 14rem" placeholder="Select a City">
|
|
|
|
<template #option="slotProps">
|
|
|
|
<div class="country-item">
|
|
|
|
<img src="https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png" v-if="slotProps.option.states" />
|
|
|
|
<i class="pi pi-compass p-mr-2" v-if="slotProps.option.cities"></i>
|
|
|
|
<i class="pi pi-map-marker p-mr-2" v-if="slotProps.option.cname"></i>
|
|
|
|
<span>{{slotProps.option.cname || slotProps.option.name}}</span>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
</CascadeSelect>
|
2021-05-14 09:01:25 +00:00
|
|
|
|
|
|
|
<h5>Loading State</h5>
|
|
|
|
<CascadeSelect placeholder="Loading..." loading style="minWidth: 14rem"></CascadeSelect>
|
2021-03-18 10:41:31 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import { ref } from 'vue';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
setup() {
|
|
|
|
const selectedCity1 = ref();
|
|
|
|
const selectedCity2 = ref();
|
|
|
|
const countries = ref([
|
|
|
|
{
|
|
|
|
name: 'Australia',
|
|
|
|
code: 'AU',
|
|
|
|
states: [
|
|
|
|
{
|
|
|
|
name: 'New South Wales',
|
|
|
|
cities: [
|
|
|
|
{cname: 'Sydney', code: 'A-SY'},
|
|
|
|
{cname: 'Newcastle', code: 'A-NE'},
|
|
|
|
{cname: 'Wollongong', code: 'A-WO'}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Queensland',
|
|
|
|
cities: [
|
|
|
|
{cname: 'Brisbane', code: 'A-BR'},
|
|
|
|
{cname: 'Townsville', code: 'A-TO'}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Canada',
|
|
|
|
code: 'CA',
|
|
|
|
states: [
|
|
|
|
{
|
|
|
|
name: 'Quebec',
|
|
|
|
cities: [
|
|
|
|
{cname: 'Montreal', code: 'C-MO'},
|
|
|
|
{cname: 'Quebec City', code: 'C-QU'}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Ontario',
|
|
|
|
cities: [
|
|
|
|
{cname: 'Ottawa', code: 'C-OT'},
|
|
|
|
{cname: 'Toronto', code: 'C-TO'}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'United States',
|
|
|
|
code: 'US',
|
|
|
|
states: [
|
|
|
|
{
|
|
|
|
name: 'California',
|
|
|
|
cities: [
|
|
|
|
{cname: 'Los Angeles', code: 'US-LA'},
|
|
|
|
{cname: 'San Diego', code: 'US-SD'},
|
|
|
|
{cname: 'San Francisco', code: 'US-SF'}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Florida',
|
|
|
|
cities: [
|
|
|
|
{cname: 'Jacksonville', code: 'US-JA'},
|
|
|
|
{cname: 'Miami', code: 'US-MI'},
|
|
|
|
{cname: 'Tampa', code: 'US-TA'},
|
|
|
|
{cname: 'Orlando', code: 'US-OR'}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Texas',
|
|
|
|
cities: [
|
|
|
|
{cname: 'Austin', code: 'US-AU'},
|
|
|
|
{cname: 'Dallas', code: 'US-DA'},
|
|
|
|
{cname: 'Houston', code: 'US-HO'}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
|
|
|
return { selectedCity1, selectedCity2, countries }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
<\\/script>
|
|
|
|
|
|
|
|
<style>
|
2021-01-21 08:40:52 +00:00
|
|
|
img {
|
|
|
|
width: 18px;
|
|
|
|
margin-right: 0.5rem;
|
|
|
|
}
|
2021-03-18 10:41:31 +00:00
|
|
|
</style>
|
2021-10-11 13:51:36 +00:00
|
|
|
`
|
|
|
|
},
|
|
|
|
'browser-source': {
|
|
|
|
tabName: 'Browser Source',
|
|
|
|
imports: `<script src="https://unpkg.com/primevue@^3/cascadeselect/cascadeselect.min.js"><\\/script>`,
|
|
|
|
content: `
|
|
|
|
<div id="app">
|
|
|
|
<h5>Basic</h5>
|
|
|
|
<p-cascadeselect v-model="selectedCity1" :options="countries" option-label="cname" option-group-label="name"
|
|
|
|
:option-group-children="['states', 'cities']" style="minWidth: 14rem" placeholder="Select a City"></p-cascadeselect>
|
|
|
|
|
|
|
|
<h5>Templating</h5>
|
|
|
|
<p-cascadeselect v-model="selectedCity2" :options="countries" option-label="cname" option-group-label="name"
|
|
|
|
:option-group-children="['states', 'cities']" style="minWidth: 14rem" placeholder="Select a City">
|
|
|
|
<template #option="slotProps">
|
|
|
|
<div class="country-item">
|
|
|
|
<img src="https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png" v-if="slotProps.option.states" />
|
|
|
|
<i class="pi pi-compass p-mr-2" v-if="slotProps.option.cities"></i>
|
|
|
|
<i class="pi pi-map-marker p-mr-2" v-if="slotProps.option.cname"></i>
|
|
|
|
<span>{{slotProps.option.cname || slotProps.option.name}}</span>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
</p-cascadeselect>
|
|
|
|
|
|
|
|
<h5>Loading State</h5>
|
|
|
|
<p-cascadeselect placeholder="Loading..." loading style="minWidth: 14rem"></p-cascadeselect>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<script type="module">
|
|
|
|
const { createApp, ref } = Vue;
|
|
|
|
|
|
|
|
const App = {
|
|
|
|
setup() {
|
|
|
|
const selectedCity1 = ref();
|
|
|
|
const selectedCity2 = ref();
|
|
|
|
const countries = ref([
|
|
|
|
{
|
|
|
|
name: 'Australia',
|
|
|
|
code: 'AU',
|
|
|
|
states: [
|
|
|
|
{
|
|
|
|
name: 'New South Wales',
|
|
|
|
cities: [
|
|
|
|
{cname: 'Sydney', code: 'A-SY'},
|
|
|
|
{cname: 'Newcastle', code: 'A-NE'},
|
|
|
|
{cname: 'Wollongong', code: 'A-WO'}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Queensland',
|
|
|
|
cities: [
|
|
|
|
{cname: 'Brisbane', code: 'A-BR'},
|
|
|
|
{cname: 'Townsville', code: 'A-TO'}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Canada',
|
|
|
|
code: 'CA',
|
|
|
|
states: [
|
|
|
|
{
|
|
|
|
name: 'Quebec',
|
|
|
|
cities: [
|
|
|
|
{cname: 'Montreal', code: 'C-MO'},
|
|
|
|
{cname: 'Quebec City', code: 'C-QU'}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Ontario',
|
|
|
|
cities: [
|
|
|
|
{cname: 'Ottawa', code: 'C-OT'},
|
|
|
|
{cname: 'Toronto', code: 'C-TO'}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'United States',
|
|
|
|
code: 'US',
|
|
|
|
states: [
|
|
|
|
{
|
|
|
|
name: 'California',
|
|
|
|
cities: [
|
|
|
|
{cname: 'Los Angeles', code: 'US-LA'},
|
|
|
|
{cname: 'San Diego', code: 'US-SD'},
|
|
|
|
{cname: 'San Francisco', code: 'US-SF'}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Florida',
|
|
|
|
cities: [
|
|
|
|
{cname: 'Jacksonville', code: 'US-JA'},
|
|
|
|
{cname: 'Miami', code: 'US-MI'},
|
|
|
|
{cname: 'Tampa', code: 'US-TA'},
|
|
|
|
{cname: 'Orlando', code: 'US-OR'}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Texas',
|
|
|
|
cities: [
|
|
|
|
{cname: 'Austin', code: 'US-AU'},
|
|
|
|
{cname: 'Dallas', code: 'US-DA'},
|
|
|
|
{cname: 'Houston', code: 'US-HO'}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
|
|
|
return { selectedCity1, selectedCity2, countries }
|
|
|
|
},
|
|
|
|
components: {
|
|
|
|
"p-cascadeselect": primevue.cascadeselect
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
createApp(App)
|
|
|
|
.use(primevue.config.default)
|
|
|
|
.mount("#app");
|
|
|
|
<\\/script>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
img {
|
|
|
|
width: 18px;
|
|
|
|
margin-right: 0.5rem;
|
|
|
|
}
|
|
|
|
</style>
|
2021-03-18 10:41:31 +00:00
|
|
|
`
|
2021-01-21 08:40:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-04-30 06:55:54 +00:00
|
|
|
</script>
|