Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

alexrobinson's avatar

InertiaJS / useForm / Bool Values and checkboxes not registering

Hi All,

I've got two checkboxes on useForm that when writing to the table translate to 0/1 bit values. I understand this is the most efficient way to write bools to an SQL table.

My "Edit" form is the same as my "Create" form. When editing, it will populate the use form values. If you're creating a new report, the values are set to default.

My issue is, when I get the data back from the table, useForm doesn't recognize the value and set the checkboxes to their correct state unless I add this below the useForm.

form.qualityIncidentReport = form.qualityIncidentReport == 1 ? true : false; 
form.employeeAtFault = form.employeeAtFault == 1 ? true : false; 

The issue is that setting the values this way creates false positives for the the getChanges()/isDirty() methods.

When I use VueDev tools after loading a report to edit, the values show 0 or 1. If I check or uncheck they change to true/false as they're supposed to be. What's the most effective way to get the v-model to recognize that when the checkbox value is 1, it should be "checked" and vice versa. Trying to use best practices here but I haven't been able to find anything.

Below you'll see where if I receive NCR prop, it'll populate the useForm fields, if not, it sets the to null.

Create.vue

const form = props.ncr ? useForm(props.ncr) : useForm({
    
    status: null,
    type: null,
    severity: null,
    qualityIncidentReport: false,

    division: null,
    incidentDate: null,
    facilityQualityManager: null,
    facilityGeneralManager: null,
    jobNo: null,
    quantityNonConforming: null,
    equipment: null,
    equipmentDescription: null,
    assemblyPartNo: null,
    drawingProcedureNo: null,
    reportDescription: null,

    employeeInvolved: null,
    employeeSupervisor: null,
    departmentInvolved: null,
    employeeAtFault: false,
    generatingBusinessUnit: null,
    purchaseOrderNo: null,
    
    repairCost: null,
    costDescription: null,
    sixMRootCause : null,
    CAPA: null,
});

...

<input type="checkbox" title="qualityIncidentReport"  v-model="form.qualityIncidentReport" :checked="form.qualityIncidentReport"/>
                            

I thought maybe using the :checked v-bind would help but it doesn't.

Let me know if you need more informatoin.

0 likes
2 replies
alexrobinson's avatar

I just tried moving this above the useForm

props.ncr.qualityIncidentReport = props.ncr.qualityIncidentReport == 1 ? true : false; 
props.ncr.employeeAtFault = props.ncr.employeeAtFault == 1 ? true : false; 

But this still triggers the isDirty() flag. I know there has to be a better way and it's probably easy and I'm just a dumby

alexrobinson's avatar
alexrobinson
OP
Best Answer
Level 1

Ok yeah, I figured it out. ALl I had to do was set these values on the input box. I found this looking at the Form Input Bindings page of Vue.JS.

<input type="checkbox" true-value="1" false-value="0"/>

Please or to participate in this conversation.