Support

Account

Home Forums ACF PRO Unable to delete hidden field

Solving

Unable to delete hidden field

  • Hey Elliot,

    This probably carries over from version 4, but I haven’t checked. I have a conditional statement set up on a parallax frame.

    Background: [Select – default/color/image]
    Background Image: [Media Uploader] (requires image type)
    Background Color: [Color Picker] (requires color type)

    1. Set to image, add image, save.
    2. Change mind, switch to color, set, save
    3. Parallax class checks for $pframe->image, is not empty, outputs
    4. Background-image overrides background-color. Rock beats scissors. Paper laughs.
    5. Attempt to remove image, but image is a required field (must select image!)
    6. Remove image, switch back to “color”, save
    7. ACF does not remove the image because the field is hidden
    8. Paper laughs at scissors again. Repeat process.

    Bottom line – if a hidden field is unset, then a conditional value is changed, the hidden field still needs to update the database.

  • there are 3 way so solve that problem:

    • let parallax check first if select is set to color or not.
    • solve problem at save_post action (delete image if select is color)
    • use a flexible field (default/color/image layout) and min:1 max:1 Layout instead of select & conditional filter

    because with a conditional filter you just hide the field at backend, value remains inside DB

  • All good advice, thanks. I really need to learn more about flexible fields – it’s one area of ACF I’ve never done anything with.

    I still think if I remove an image, then switch the field type (conditionally hiding the image field itself), that ACF should honor the removal. So from an engineering point of view, you make elegant suggestions. From the standpoint of the bug report, I still feel some work could be done 🙂

  • as far as i understand:
    conditionally hiding save only visible field. that why it allows you to skip some “may required” fields. it never does or should delete saved values by switch condition.
    if you delete something and switch. delete is not saved because everything is only saved when it is visible and you click save.

    to be fair/true: 😉 your main problem is not hidden or not hidden, you try to delete a required field. and a required field is like a radio-button with 1 value. you cant deselect it once set. this is something that is not possible without additional coding or a workaround.

    one way to remove a value from DB set by required-field is:
    set it to not required, delete value, and save. after that set it back to required.
    but that is not practical 😉 and nothing a customer should be able to do.

    what (may) should work too is: duplicate image-field (same field-name!)
    show it at color but set it as not required. (set conditionals same as color)
    let original required at image conditional.
    if you switch from image to color: required image set by image is shown as not required at color. image can be deleted there because it is not required.
    with that it can be saved, but customer had to delete it manually.

    it may could work with a update_value filter and wp_update_post too

    but my advise: solve problem at save_post action or with flexible field

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Unable to delete hidden field’ is closed to new replies.