fix: explain missing funding search criteria instead of disabling submit

This commit is contained in:
2026-11-23 11:21:27 +02:00
parent fdea11ae50
commit 3267c10e6b
17 changed files with 621 additions and 17 deletions
+59 -11
View File
@@ -64,6 +64,7 @@ function Index({
criteriaErrors?: Record<string, string[]>;
}) {
const [notice, setNotice] = useState('');
const [searchAttempted, setSearchAttempted] = useState(false);
const [searchTerritory, setSearchTerritory] = useState(territorySelection);
const form = useForm({
category: filters.category ?? '',
@@ -93,6 +94,12 @@ function Index({
const searchReady = Boolean(
form.data.need && (form.data.territory || form.data.province_id),
);
const missingSearchCriteria = [
...(!form.data.need ? ['Seleccione a necessidade do processo.'] : []),
...(!(form.data.territory || form.data.province_id)
? ['Seleccione a província ou outra localização de interesse.']
: []),
];
const typeAllowed = (category: string, type: string) =>
!category ||
category === 'other' ||
@@ -118,7 +125,18 @@ function Index({
className={`${card} flex flex-wrap gap-4 [&_select]:w-full [&_select]:max-w-full [&_select]:min-w-0 [&>label]:w-full [&>label]:max-w-full [&>label]:min-w-0 sm:[&>label]:w-auto`}
onSubmit={(e) => {
e.preventDefault();
if (!searchReady) return;
if (!searchReady) {
setSearchAttempted(true);
const target = !form.data.need
? e.currentTarget?.querySelector<HTMLElement>(
'[name="need"]',
)
: e.currentTarget?.querySelector<HTMLElement>(
'[data-funding-location] input[role="combobox"]',
);
target?.focus();
return;
}
form.get('/fundos');
}}
>
@@ -257,13 +275,21 @@ function Index({
tal
</label>
<label>
Necessidade do processo
Necessidade do processo (obrigatória)
<select
name="need"
aria-label="Necessidade do processo"
aria-invalid={
(searchAttempted && !form.data.need) || undefined
}
aria-describedby={
!searchReady ? 'funding-search-minimum' : undefined
}
className="block rounded border p-2"
value={form.data.need}
onChange={(e) => form.setData('need', e.target.value)}
>
<option value="">Todas / por identificar</option>
<option value="">Seleccione a necessidade</option>
{Object.entries(needs).map(([id, label]) => (
<option key={id} value={id}>
{label}
@@ -314,9 +340,16 @@ function Index({
))}
</select>
</label>
<fieldset className="min-w-0 basis-full">
<fieldset
data-funding-location
className="min-w-0 basis-full"
aria-describedby={
!searchReady ? 'funding-search-minimum' : undefined
}
>
<legend>
Local de interesse — seleccione até ao nível conhecido
Local de interesse (obrigatório) — seleccione até ao
nível conhecido
</legend>
<label>
Localização a pesquisar
@@ -411,19 +444,34 @@ function Index({
</select>
</label>
{!searchReady && (
<p id="funding-search-minimum" role="status">
Escolha a localização a pesquisar e a necessidade do
processo antes de pesquisar.
</p>
<div
id="funding-search-minimum"
role={searchAttempted ? 'alert' : 'status'}
className={
searchAttempted
? 'basis-full rounded border border-amber-600 p-3'
: 'basis-full text-sm'
}
>
{searchAttempted && (
<p className="font-semibold">
A pesquisa não foi executada. Complete os campos
indicados.
</p>
)}
{missingSearchCriteria.map((message) => (
<p key={message}>{message}</p>
))}
</div>
)}
<button
className={button}
disabled={form.processing || !searchReady}
disabled={form.processing}
aria-describedby={
!searchReady ? 'funding-search-minimum' : undefined
}
>
Pesquisar
{form.processing ? 'A pesquisar…' : 'Pesquisar'}
</button>
</form>
{criteriaChanged && (