fix: errors, remove handleChange

This commit is contained in:
EETagent 2023-01-17 00:02:37 +01:00
parent 2776452046
commit 3233945dd4
2 changed files with 7 additions and 45 deletions

View file

@ -23,7 +23,7 @@
}; };
}); });
export let error: string = ''; export let error: string | Array<unknown> = '';
export let grades: Array<GradeBackend>; export let grades: Array<GradeBackend>;
@ -66,7 +66,7 @@
<GradesRow on:keyup={convertGrades} on:change={convertGrades} bind:grade={gradesLocal[i]} /> <GradesRow on:keyup={convertGrades} on:change={convertGrades} bind:grade={gradesLocal[i]} />
{/each} {/each}
<button <button
class:isError={error} class:isError={error.length > 0}
class="ml-auto w-24 rounded-full bg-gray-400 p-1 text-xl text-white transition-colors duration-300 hover:bg-gray-500" class="ml-auto w-24 rounded-full bg-gray-400 p-1 text-xl text-white transition-colors duration-300 hover:bg-gray-500"
on:click={() => { on:click={() => {
gradesLocal = [ gradesLocal = [
@ -83,13 +83,6 @@
]; ];
}}>+</button }}>+</button
> >
<button
class="ml-auto w-24 rounded-full bg-gray-400 p-1 text-xl text-white transition-colors duration-300 hover:bg-gray-500"
on:click={() => {
alert(JSON.stringify(gradesLocal));
alert(JSON.stringify(grades));
}}>+</button
>
</div> </div>
<style lang="postcss"> <style lang="postcss">

View file

@ -120,7 +120,7 @@
semester: yup.string().required() semester: yup.string().required()
}) })
.required() .required()
) ).required()
}), }),
parents: yup.array().of( parents: yup.array().of(
yup.object().shape({ yup.object().shape({
@ -286,7 +286,7 @@
} }
}; };
const { form, errors, handleSubmit, handleChange } = createForm({ const { form, errors, handleSubmit } = createForm({
initialValues: formInitialValues, initialValues: formInitialValues,
validationSchema: formValidationSchema, validationSchema: formValidationSchema,
@ -359,6 +359,9 @@
return true; return true;
} }
break; break;
case 7:
if ($typedErrors["candidate"]["grades"].length > 0) return true;
break;
default: default:
return false; return false;
} }
@ -430,7 +433,6 @@
applications={baseCandidateDetails.applications} applications={baseCandidateDetails.applications}
bind:linkOk={$form.linkOk} bind:linkOk={$form.linkOk}
bind:linkError={$form.linkError} bind:linkError={$form.linkError}
on:change={handleChange}
error={$typedErrors['linkOk']} error={$typedErrors['linkOk']}
/> />
</div> </div>
@ -446,7 +448,6 @@
</p> </p>
<div class="field"> <div class="field">
<GdprCheckBox <GdprCheckBox
on:change={handleChange}
bind:value={$form.gdpr} bind:value={$form.gdpr}
error={$typedErrors['gdpr']} error={$typedErrors['gdpr']}
/> />
@ -463,7 +464,6 @@
<span class="field"> <span class="field">
<NameField <NameField
error={$typedErrors['candidate']['name'] || $typedErrors['candidate']['surname']} error={$typedErrors['candidate']['name'] || $typedErrors['candidate']['surname']}
on:change={handleChange}
bind:valueName={$form.candidate.name} bind:valueName={$form.candidate.name}
bind:valueSurname={$form.candidate.surname} bind:valueSurname={$form.candidate.surname}
placeholder="Jméno a příjmení" placeholder="Jméno a příjmení"
@ -472,7 +472,6 @@
<span class="field"> <span class="field">
<EmailField <EmailField
error={$typedErrors['candidate']['email']} error={$typedErrors['candidate']['email']}
on:change={handleChange}
bind:value={$form.candidate.email} bind:value={$form.candidate.email}
placeholder="E-mail" placeholder="E-mail"
/> />
@ -480,7 +479,6 @@
<span class="field"> <span class="field">
<TelephoneField <TelephoneField
error={$typedErrors['candidate']['telephone']} error={$typedErrors['candidate']['telephone']}
on:change={handleChange}
bind:value={$form.candidate.telephone} bind:value={$form.candidate.telephone}
placeholder="Telefon" placeholder="Telefon"
/> />
@ -498,7 +496,6 @@
<NameField <NameField
error={$typedErrors['candidate']['street'] || error={$typedErrors['candidate']['street'] ||
$typedErrors['candidate']['houseNumber']} $typedErrors['candidate']['houseNumber']}
on:change={handleChange}
bind:valueName={$form.candidate.street} bind:valueName={$form.candidate.street}
bind:valueSurname={$form.candidate.houseNumber} bind:valueSurname={$form.candidate.houseNumber}
placeholder="Ulice a č. p." placeholder="Ulice a č. p."
@ -508,7 +505,6 @@
<span class="ml-2 w-[33%]"> <span class="ml-2 w-[33%]">
<TextField <TextField
error={$typedErrors['candidate']['zip']} error={$typedErrors['candidate']['zip']}
on:change={handleChange}
bind:value={$form.candidate.zip} bind:value={$form.candidate.zip}
type="number" type="number"
placeholder="PSČ" placeholder="PSČ"
@ -520,7 +516,6 @@
<span> <span>
<TextField <TextField
error={$typedErrors['candidate']['city']} error={$typedErrors['candidate']['city']}
on:change={handleChange}
bind:value={$form.candidate.city} bind:value={$form.candidate.city}
type="text" type="text"
placeholder="Město" placeholder="Město"
@ -530,7 +525,6 @@
<span class="ml-2"> <span class="ml-2">
<TextField <TextField
error={$typedErrors['candidate']['birthplace']} error={$typedErrors['candidate']['birthplace']}
on:change={handleChange}
bind:value={$form.candidate.birthplace} bind:value={$form.candidate.birthplace}
type="text" type="text"
placeholder="Místo narození" placeholder="Místo narození"
@ -547,7 +541,6 @@
<div class="field flex items-center"> <div class="field flex items-center">
<TextField <TextField
error={$typedErrors['candidate']['birthdate']} error={$typedErrors['candidate']['birthdate']}
on:change={handleChange}
bind:value={$form.candidate.birthdate} bind:value={$form.candidate.birthdate}
type="text" type="text"
placeholder="Datum narození" placeholder="Datum narození"
@ -556,7 +549,6 @@
<div class="ml-2"> <div class="ml-2">
<SelectField <SelectField
error={$typedErrors['candidate']['sex']} error={$typedErrors['candidate']['sex']}
on:change={handleChange}
bind:value={$form.candidate.sex} bind:value={$form.candidate.sex}
options={['Žena', 'Muž']} options={['Žena', 'Muž']}
placeholder="Pohlaví" placeholder="Pohlaví"
@ -572,7 +564,6 @@
<span class="field"> <span class="field">
<NameField <NameField
error={$typedErrors['parents'][0]['name'] || $typedErrors['parents'][0]['surname']} error={$typedErrors['parents'][0]['name'] || $typedErrors['parents'][0]['surname']}
on:change={handleChange}
bind:valueName={$form.parents[0].name} bind:valueName={$form.parents[0].name}
bind:valueSurname={$form.parents[0].surname} bind:valueSurname={$form.parents[0].surname}
placeholder="Jméno a příjmení zákonného zástupce" placeholder="Jméno a příjmení zákonného zástupce"
@ -581,7 +572,6 @@
<span class="field"> <span class="field">
<EmailField <EmailField
error={$typedErrors['parents'][0]['email']} error={$typedErrors['parents'][0]['email']}
on:change={handleChange}
bind:value={$form.parents[0].email} bind:value={$form.parents[0].email}
placeholder="E-mail zákonného zástupce" placeholder="E-mail zákonného zástupce"
/> />
@ -589,7 +579,6 @@
<span class="field"> <span class="field">
<TelephoneField <TelephoneField
error={$typedErrors['parents'][0]['telephone']} error={$typedErrors['parents'][0]['telephone']}
on:change={handleChange}
bind:value={$form.parents[0].telephone} bind:value={$form.parents[0].telephone}
placeholder="Telefon zákonného zástupce" placeholder="Telefon zákonného zástupce"
/> />
@ -604,7 +593,6 @@
<span class="field"> <span class="field">
<NameField <NameField
error={$typedErrors['parents'][1]['name'] || $typedErrors['parents'][1]['surname']} error={$typedErrors['parents'][1]['name'] || $typedErrors['parents'][1]['surname']}
on:change={handleChange}
bind:valueName={$form.parents[1].name} bind:valueName={$form.parents[1].name}
bind:valueSurname={$form.parents[1].surname} bind:valueSurname={$form.parents[1].surname}
placeholder="Jméno a příjmení zákonného zástupce (nepovinné)" placeholder="Jméno a příjmení zákonného zástupce (nepovinné)"
@ -613,7 +601,6 @@
<span class="field"> <span class="field">
<EmailField <EmailField
error={$typedErrors['parents'][1]['email']} error={$typedErrors['parents'][1]['email']}
on:change={handleChange}
bind:value={$form.parents[1].email} bind:value={$form.parents[1].email}
placeholder="E-mail zákonného zástupce (nepovinné)" placeholder="E-mail zákonného zástupce (nepovinné)"
/> />
@ -621,7 +608,6 @@
<span class="field"> <span class="field">
<TelephoneField <TelephoneField
error={$typedErrors['parents'][1]['telephone']} error={$typedErrors['parents'][1]['telephone']}
on:change={handleChange}
bind:value={$form.parents[1].telephone} bind:value={$form.parents[1].telephone}
placeholder="Telefon zákonného zástupce (nepovinné)" placeholder="Telefon zákonného zástupce (nepovinné)"
/> />
@ -637,7 +623,6 @@
<span class="field"> <span class="field">
<SelectField <SelectField
error={$typedErrors['candidate']['citizenship']} error={$typedErrors['candidate']['citizenship']}
on:change={handleChange}
bind:value={$form.candidate.citizenship} bind:value={$form.candidate.citizenship}
placeholder="Občanství" placeholder="Občanství"
options={['Česká republika', 'Slovenská republika', 'Ukrajina', 'Jiné']} options={['Česká republika', 'Slovenská republika', 'Ukrajina', 'Jiné']}
@ -648,7 +633,6 @@
{#if $form.candidate.citizenship === 'Česká republika' || !$form.candidate.citizenship} {#if $form.candidate.citizenship === 'Česká republika' || !$form.candidate.citizenship}
<TextField <TextField
error={$typedErrors['candidate']['schoolName']} error={$typedErrors['candidate']['schoolName']}
on:change={handleChange}
type="number" type="number"
bind:value={$form.candidate.schoolName} bind:value={$form.candidate.schoolName}
placeholder="IZO školy" placeholder="IZO školy"
@ -656,7 +640,6 @@
{:else} {:else}
<TextField <TextField
error={$typedErrors['candidate']['schoolName']} error={$typedErrors['candidate']['schoolName']}
on:change={handleChange}
type="text" type="text"
bind:value={$form.candidate.schoolName} bind:value={$form.candidate.schoolName}
placeholder="Název školy" placeholder="Název školy"
@ -667,7 +650,6 @@
<span class="ml-2"> <span class="ml-2">
<TextField <TextField
error={$typedErrors['candidate']['healthInsurance']} error={$typedErrors['candidate']['healthInsurance']}
on:change={handleChange}
type="text" type="text"
bind:value={$form.candidate.healthInsurance} bind:value={$form.candidate.healthInsurance}
placeholder="Číslo zdravotní pojišťovny" placeholder="Číslo zdravotní pojišťovny"
@ -679,14 +661,12 @@
{#if $form.candidate.citizenship === 'Česká republika' || !$form.candidate.citizenship} {#if $form.candidate.citizenship === 'Česká republika' || !$form.candidate.citizenship}
<IdField <IdField
error={$typedErrors['candidate']['personalIdNumber']} error={$typedErrors['candidate']['personalIdNumber']}
on:change={handleChange}
bind:value={$form.candidate.personalIdNumber} bind:value={$form.candidate.personalIdNumber}
placeholder="Rodné číslo" placeholder="Rodné číslo"
/> />
{:else} {:else}
<TextField <TextField
error={$typedErrors['candidate']['personalIdNumber']} error={$typedErrors['candidate']['personalIdNumber']}
on:change={handleChange}
bind:value={$form.candidate.personalIdNumber} bind:value={$form.candidate.personalIdNumber}
placeholder="Rodné číslo" placeholder="Rodné číslo"
/> />
@ -699,17 +679,6 @@
</p> </p>
<GradesTable <GradesTable
error={$typedErrors['candidate']['grades']} error={$typedErrors['candidate']['grades']}
on:change={(event) => {
//@ts-ignore
const mockEvent = {
target: {
name: 'candidate.grades',
value: event.detail
}
};
//@ts-ignore
handleChange(mockEvent);
}}
bind:grades={$form.candidate.grades} bind:grades={$form.candidate.grades}
/> />
{/if} {/if}