Forms

Int4RangeInput

Input per range di interi PostgreSQL (tipo int4range). Emette e accetta il formato stringa PostgreSQL con notazione inclusiva/esclusiva dei bound (es. "[1,10)").

Import

import { Int4RangeInput } from '@pzeta/vue-components'

Esempio Base

<script setup lang="ts">
import { ref } from 'vue'
import { Int4RangeInput } from '@pzeta/vue-components'

const rangeValue = ref<string | null>(null)
</script>

<template>
  <Int4RangeInput v-model="rangeValue" label="Range numerico" />
  <p>Valore PostgreSQL: {{ rangeValue }}</p>
</template>

Il componente emette sempre il valore in formato stringa PostgreSQL int4range (es. "[1,10)"). Accetta in ingresso sia la stringa che un oggetto Int4Range.

Formato Valore

FormatoEsempioSignificato
[min,max)[1,10)min incluso, max escluso (default PostgreSQL)
[min,max][1,10]entrambi inclusi
(min,max)(1,10)entrambi esclusi
(min,max](1,10]min escluso, max incluso
nullnullnessun valore

I simboli [ e ] indicano il bound incluso (>=, <=). I simboli ( e ) indicano il bound escluso (>, <). L'utente puo cliccare sulle parentesi nell'UI per cambiarle.

Props

PropTipoDefaultDescrizione
modelValuestring | Int4Range | nullnullValore corrente (v-model)
labelstringLabel del componente
minPlaceholderstring'Min'Placeholder del campo minimo
maxPlaceholderstring'Max'Placeholder del campo massimo
minLabelstring'Da'Label del campo minimo
maxLabelstring'A'Label del campo massimo
helperTextstringTesto di aiuto
errorstringMessaggio di errore
requiredbooleanfalseCampo obbligatorio
disabledbooleanfalseDisabilita il componente
loadingbooleanfalseMostra stato di caricamento
invalidbooleanfalseForza stato errore
size'small' | 'medium' | 'large''medium'Dimensione degli InputNumber interni
severitySeverity'primary'Colore del tema
minnumberValore minimo consentito
maxnumberValore massimo consentito
stepnumberStep per incremento/decremento
minInclusiveTooltipstring'Incluso'Tooltip parentesi minimo inclusivo
minExclusiveTooltipstring'Escluso'Tooltip parentesi minimo esclusivo
maxInclusiveTooltipstring'Incluso'Tooltip parentesi massimo inclusivo
maxExclusiveTooltipstring'Escluso'Tooltip parentesi massimo esclusivo
classstringClasse CSS aggiuntiva

Emits

EventoPayloadDescrizione
update:modelValuestring | nullAggiornamento valore in formato PostgreSQL
focusFocusEventFocus su uno degli input
blurFocusEventBlur da uno degli input

Tipo Int4Range

interface Int4Range {
  min: number | null
  max: number | null
  minInclusive?: boolean  // default: true  (parentesi '[')
  maxInclusive?: boolean  // default: false (parentesi ')')
}

Esempi

Con valore predefinito

Con limiti e step

Bounds inclusivi/esclusivi personalizzati

L'utente puo cliccare visivamente sulle parentesi nell'UI per cambiare la modalita inclusivo/esclusivo. Il valore emesso riflette immediatamente la modifica.

Integrazione con query PostgreSQL

<script setup lang="ts">
const ageRange = ref<string | null>('[18,65)')

async function search() {
  // Il valore e gia in formato PostgreSQL int4range
  const result = await db.query(
    'SELECT * FROM anagrafica WHERE eta <@ $1::int4range',
    [ageRange.value]
  )
}
</script>

<template>
  <Int4RangeInput v-model="ageRange" label="Fascia eta" />
  <button @click="search">Cerca</button>
</template>

Stati

Legenda Simboli PostgreSQL

SimboloSignificatoEsempio SQL
[bound minimo inclusox >= min
(bound minimo esclusox > min
]bound massimo inclusox <= max
)bound massimo esclusox < max

TypeScript

import type { Int4RangeInputProps, Int4Range } from '@pzeta/vue-components'

// Formato stringa PostgreSQL
const range = ref<string | null>('[1,100)')

// Oppure oggetto strutturato
const rangeObj: Int4Range = {
  min: 1,
  max: 100,
  minInclusive: true,   // '['
  maxInclusive: false,  // ')'
}