You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
One of the more common use cases I have with models is using them in forms. When using a form it's nice to have that baked in with some save button state handling and navigation guards to protect changes.
Is there a flag to see if a model is dirty? I don't see one in the prototype as of now but maybe i'm missing something. The way I see it it could work like this.
<script setup>
// ... assume loaded my model correctly up here
const model = MyModel({a, b, c});
const form = model.clone();
const submit = async () => {
await form.save();
form.commit();
}
</script>
<template @submit.prevent="submit">
<form>
<label>A</label><input v-model="form.a" />
<label>B</label><input v-model="form.b" />
<label>C</label><input v-model="form.c" />
<button type="submit" :disabled="!form.__isDirty" />
</form>
</template>
That's a basic use case. I guess in lieu of something existing on the model we could do model === form ?
Interested to know if there's already a convention for this.
The text was updated successfully, but these errors were encountered:
If you haven't checked out Formkit, I'd recommend giving it a shot. It kinda handles the overhead for you. You don't have to
manually bind v-model to elements. It handles reset states, too. Pretty impressive. https://formkit.com/
One of the more common use cases I have with models is using them in forms. When using a form it's nice to have that baked in with some save button state handling and navigation guards to protect changes.
Is there a flag to see if a model is dirty? I don't see one in the prototype as of now but maybe i'm missing something. The way I see it it could work like this.
That's a basic use case. I guess in lieu of something existing on the model we could do
model === form
?Interested to know if there's already a convention for this.
The text was updated successfully, but these errors were encountered: