kenoxa / svelte-formup Goto Github PK
View Code? Open in Web Editor NEWforms with yup for svelte
Home Page: https://svelte-formup.js.org
License: MIT License
forms with yup for svelte
Home Page: https://svelte-formup.js.org
License: MIT License
Hi Sascha,
I'm displaying a form with a single field.
When selecting the field, the $dirty store does not update. It remains an empty object.
When I enter a text and delete it again, the $errors and $invalid store do not update either. Both remain empty objects.
{ "values": { "bpm_comment": "" }, "invalid": {}, "errors": {}, "dirty": {} }
I'm using
Here is my code:
<script lang="ts">
import { object, string } from 'yup'
import { formup } from 'svelte-formup'
const schema = object().shape({
bpm_comment: string().required(),
})
const { values, validate, invalid, errors, dirty, validity } = formup({
getInitialValues: () => ({
bpm_comment: undefined,
}),
validateOn: ['input', 'change'],
schema,
validateInitialValues: true,
async onSubmit(data, _) {
console.log({ data })
},
})
</script>
<form use:validate role="form">
<div use:validity>
<textarea
id={'bpm_comment'}
name="bpm_comment"
label="Comment (optional)"
rows={3}
bind:value={$values.bpm_comment} />
</div>
<p>
<button type="submit">Submit</button>
<button type="reset">reset</button></p>
</form>
{JSON.stringify({ values: $values, invalid: $invalid, errors: $errors, dirty: $dirty }, null, 4)}
Hi Sascha,
When rendering the form initially with validateInitialValues: true
, the $invalid stores is empty and $invalid.get("bwcl_employee") returns undefined
.
When selecting a different value and then selecting the initial value ("undefined") again, the errors shows correctly:
ValidationError: bwcl_employee is a required field
I'm using
Here is my code:
<script lang="ts">
import { object, string } from 'yup'
import { formup } from 'svelte-formup'
const schema = object().shape({
bwcl_employee: object({
id: string().required(),
manager: object()
.shape({
id: string().required(),
})
.required(),
})
.required()
.defined(),
})
schema.validate({}, { abortEarly: false }).catch((error) => {
console.log({ error })
})
const { values, validate, invalid, errors, dirty, validity, isDirty, isError } = formup({
getInitialValues: () => ({
bwcl_employee: undefined,
}),
validateOn: ['input', 'change'],
schema,
validateInitialValues: true,
onSubmit(data, _) {
console.log({ data })
},
})
</script>
<form use:validate role="form">
<div use:validity>
<select id="bwcl_employee" name="bwcl_employee" bind:value={$values.bwcl_employee}>
<option>please select</option>
<option value={{ name: 'hans' }}>xy</option>
<option value={{ id: 'xy', name: 'hans' }}>xy</option>
<option value={{ id: 'zw', name: 'hans' }}>zw</option>
</select>
<p>{$invalid?.get('bwcl_employee')}</p>
</div>
<p><button type="submit">Submit</button> <button type="reset">reset</button></p>
</form>
{JSON.stringify({ values: $values, invalid: $invalid, errors: $errors, dirty: $dirty, isDirty, isError }, null, 4)}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.