Hi, I am trying to set a checkbox by setting the value of its field which is attached to a node in a post request to create the node, specifically the field_mark_as_discounted of a product display. I have been unsuccessful so far. If anyone has come across the issue of trying to set a checkbox by setting the value of its corresponding field using a post request, please share.

Comments

hby01 created an issue. See original summary.

hby01’s picture

Category: Task » Support request
hby01’s picture

Title: Set Checkbox with post request » How to set Checkbox with post request?
tyler.frankenstein’s picture

If it's a boolean field, the JSON data for the particular field should look like this:

field_mark_as_discounted: { und: [ { value: 1 } ] }

Codexr’s picture

This doesn't appear to be working. I am trying the following:

field_character_type: {und: [{value: 0}]}

With no luck

I can check a checkbox but I cannot uncheck a checkbox.

tyler.frankenstein’s picture

IIRC, to uncheck a boolean, you may have to send null. Try some of these:

field_character_type: null

field_character_type: {und: null}

field_character_type: {und: [null]}

field_character_type: {und: [{value: null}]}

Things may also change if your field is required or not, so perhaps try toggling the required bit on the field instance settings to see if that changes how things behave.

jacob.embree’s picture

Assigned: hby01 » Unassigned
Status: Active » Fixed

Marking fixed because #6 looks correct and haven't heard from hby01.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

jerodfritz’s picture

After much trial and error to uncheck the checkbox the only one that works is

field_character_type: {und: null}

I would have assumed it to be:

field_character_type: {und: [{value: "0"}]}
or
field_character_type: {und: [{value: false}]}

If you want to check the checkbox you can pretty much send anything other than {und: null}. For sanity I send this:

field_character_type: {und: [{value: true}]}