2 fields with the same ID

Support General 2 fields with the same IDResolved

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #27206
    MartinMartin
    Participant

    A quick one - I have 2 select_advanced fields and I want them to both feed the same meta data. I intend to selectively show only one version of the fields.

    I have a pet_species field where I can select Dog or Cat.

    For the 2 instances of the pet_breed field I will show one version with a list of dog breeds for when pet_species is Dog and the list of cat breeds for when the pet_species is Cat.

    I fell at the first hurdle unfortunately as the Conditional Logic seems to be tied to the field ID rather than the field instance (ie when I set the pet_species = Cat it types the same thing into both field instances).

    As this is an improvement on the free text version of an existing field I'd rather not have to create a second field id to cater for the two different lists.

    Is there another way around this?

    #27215
    Long NguyenLong Nguyen
    Moderator

    Hi Martin,

    Conditional Logic uses JavaScript to find the field ID and do its function so if you use two fields with the same ID, it will not works properly in some cases.

    You can use the action rwmb_{$field_id}_after_save_field then set a field value base on another field value. Get more details on the documentation
    https://docs.metabox.io/actions/#rwmb_after_save_field
    https://docs.metabox.io/rwmb-set-meta/

    #27216
    MartinMartin
    Participant

    OK. Thanks Long.

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.