Comments (6)
I've opened #20 which allows you to pass a callback as the method / url.
<script setup>
import {useForm} from 'laravel-precognition-vue'
import {computed} from 'vue'
const props = defineProps = ({
modelValue: Boolean,
person: Object
})
const exists = computed(() => props.person?.id !== null)
const form = useForm(
() => exists.value ? 'patch' : 'post',
() => exists.value ? `/people/${person.id}` : '/people',
{
first_name: props.first_name,
last_name: props.last_name,
// ...
}
)
const submit = () => {
form.submit({
onSuccess: /* ... */,
})
}
</script>
I'll close this and we can follow the PR.
from precognition.
Usually do releases on a Tuesday.
from precognition.
Can you provide a full example of how you currently do this?
from precognition.
I have a modal dialog for create/update person records.
This is a simple example using inertiajs form
Modal.vue
<template>
<div class="modal" v-if="modelValue">
<input v-model="form.first_name" />
<input v-model="form.last_name" />
<!--- other n fields ... --->
<button @click="submit">OK</button>
</div>
</template>
<script setup>
import {useForm} from 'inertiajs/vue3'
import {computed} from 'vue'
const props = defineProps = ({
modelValue: Boolean,
person: Object
})
const emit = defineEmits(['update:modelValue'])
const form = useForm({
first_name: props.first_name,
last_name: props.last_name,
//....
})
const exists = computed(() => props.person?.id !== null)
const submit = () => {
let method, url
if (exists.value) {
method = 'patch'
url = '/people/' + person.id
} else {
method = 'post'
url = '/people'
}
form[method](url, {
onSuccess: () => emit('update:modelValue', false)
})
}
</script>
in precognition useForm
composable method
and url
are strings and cannot change their values after form object declaration.
Maybe is possible to re-declare entire object when person property changes but I think it isn't a good way
from precognition.
PR is merged when will be released?
from precognition.
Usually do releases on a Tuesday.
Sorry for writing again... but any news about release?
from precognition.
Related Issues (20)
- Error in Precognition React using Sanctum HOT 4
- Make initial value (third parameter of useForm) dynamic HOT 4
- onValidate Callback or async validate HOT 5
- Method for setting CSRF token on client HOT 4
- Form reporting incorrectly valid HOT 1
- onValidate callback or async validate (reopen) HOT 10
- Cannot use 'data' as a form property HOT 2
- Provide support for interfaces for useForm function (Vue & Inertia) HOT 1
- Live validation doesn't seem to work with Laravel 11 HOT 4
- inertia-vue - Use transformed data when validating HOT 1
- Executing code via a listener during Precognition requests leads to `ERR_CANCELED` HOT 13
- form.submit() triggers a CanceledError from Axios HOT 4
- Svelte support HOT 1
- Can we add PR for precognition with Support for React Native? HOT 3
- [inertia-vue] The `useForm` helper returns `any` type HOT 2
- Request errors never get set on form HOT 16
- Trigger validation immediately if necessary HOT 5
- Validation not triggered when Inertia `transform` changes keys. HOT 2
- Precognition is not working for the specified route HOT 6
- form.validate() does nothing HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from precognition.