0

It will read from the database and put an appropriate check in the checkbox (or leave it blank), but I can't get it to update the database when the user checks a checkbox. The other fields work, they update to the database.

<template>
    <form>
      <div>
        <div @input="update">
          <input v-model="form.month" type="text" />
          <input v-model="form.day_deposited" type="text" />
          <input v-model="form.description" type="text" />
          <input v-model="form.amount" type="text" />
          <input v-model="form.paid" type="checkbox" true-value="1" false-value="0" />
          <Link :href="`/income/${props.income.id}`" method="DELETE" as="button" preserve-scroll>Delete</Link>
        </div>
      </div>
    </form>
</template>
 
  <script setup>
  import { useForm } from '@inertiajs/vue3'
  import { Link } from '@inertiajs/vue3'
  const props = defineProps({
    income: Object
  })

  const form = useForm({
    id: props.income.id,
    month: props.income.month,
    day_deposited: props.income.day_deposited,
    description: props.income.description,
    amount: props.income.amount,
    paid: props.income.paid,
  })

  const update = () => form.put(`/income/${props.income.id}`, {preserveScroll:true})
  </script>
4
  • Have you checked your HTTP request payload to see what value is being sent to the server? Commented Dec 18, 2024 at 8:39
  • Test with postman first? Verify that the route is being properly handled? Or utilize burp suite to intercept what exactly is even being sent to the server. We need more information before we can help you debug here. Commented Dec 18, 2024 at 19:38
  • If the checkbox is empty and I check it, this is the payload: {id: 2, month: null, day_deposited: "2", description: "Cole and Sons", amount: "2934", paid: 0} amount : "2934" day_deposited : "2" description : "Cole and Sons" id : 2 month : null paid : 0 If I uncheck it, this is the payload: {id: 2, month: null, day_deposited: "2", description: "Cole and Sons", amount: "2934", paid: "1"} amount : "2934" day_deposited : "2" description : "Cole and Sons" id : 2 month : null paid : "1" "1" for unchecked and "0" for checked. Commented Dec 19, 2024 at 22:41
  • @MarianneHartigan that will be due to your true-value and false-value attributes. You can work with 1 and 0 though, so this is likely a backend issue. What does your controller look like? Are you updating a database record via its model? If so, have you added paid to the $protected properties array? Have you casted the property to a boolean? Is your database column setup correctly? We need more information to help you. Commented Dec 20, 2024 at 9:12

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.