Coder Social home page Coder Social logo

Comments (6)

timacdonald avatar timacdonald commented on August 17, 2024 1

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.

timacdonald avatar timacdonald commented on August 17, 2024 1

Usually do releases on a Tuesday.

from precognition.

timacdonald avatar timacdonald commented on August 17, 2024

Can you provide a full example of how you currently do this?

from precognition.

makroxyz avatar makroxyz commented on August 17, 2024

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.

makroxyz avatar makroxyz commented on August 17, 2024

PR is merged when will be released?

from precognition.

makroxyz avatar makroxyz commented on August 17, 2024

Usually do releases on a Tuesday.

Sorry for writing again... but any news about release?

from precognition.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.