AdvancedCustomFields / AdvancedCustomFields/acf

Setting value of Post Object field returning false

Open
#245 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
945
Forks
197
PR merge metrics
No merged PRs in 30d

Description

I'm trying to build some custom interaction which would auto-select some posts in a Post Object field based on a previously filled-in ACF field. For this I run an on.change event in a JS file which then calls the acf.getField function and tries to set the value like this:

field = acf.getField('field_5da85ee6a41e9');
field.val([255])

Problem is that this returns a false. While debugging this, I noticed that selecting and de-selecting the option, allows the code to run successfully. Here is a screenshot of doing what the JS code does except in the console where, between the two val functions I manually selected and deselected the option with ID 255.

image

Is there anything I can do to resolve this? I've tested the same functionality with a Select field with manually typed-in options and this works without a problem.

Thanks!
Freek

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the Post Object field behavior with acf.getField('field_5da85ee6a41e9') and field.val([255]), then compare it with the working Select field case. Trace the Post Object field's JavaScript value handling and determine why selecting and deselecting first changes the result. Done means setting the post ID programmatically returns the expected value without manual interaction.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, php
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.