Custom Fields
Re-Envisioned
Support Meta Box Conditional Logic Conditional Logic Not Working

  • Creator
    Topic
  • #10831
    Resolved swartjie
    Participant

    Hey Guys,

    I am having a bit of a hard time with the conditional logic on a couple of fields…
    It seems it works perfectly on all others though, So I can’t figure out what I am doing wrong…

    Can you please advise?

    The code added to the fields are as follows:

    array(
                    'id' => 'certified-load-capacity-of-concrete-floor-slab-fill-in',
                    'name' => 'Certified load capacity of concrete floor SLAB',
                    'type' => 'number',
                    'step' => '0.01',
                    'columns' => 6,
                    'tab'   =>  'site_assessment_of_the_data_center_location_2',
                    'visible' => array(
                        'when' =>
                        array(
                            array(
                                0 => 'certified-load-capacity-of-concrete-floor-slab',
                                1 => '!=',
                                2 => 'N/A',
                            ),
                            array(
                                0 => 'certified-load-capacity-of-concrete-floor-slab',
                                1 => '!=',
                                2 => 'Unknown',
                            ),
                        ),
                        'relation' => 'and',
                    )
                ),
                array(
                    'id' => 'certified-load-capacity-of-concrete-floor-slab',
                    'name' => 'Certified load capacity of concrete floor SLAB',
                    'type' => 'radio',
                    'options' => [
                        'Kg/m2' =>  'Kg/m2',
                        'Lbs/ft2'   =>  'Lbs/ft2',
                        'N/A'   =>  'N/A',
                        'Unknown'   =>  'Unknown'
                    ],
                    'inline' => 1,
                    'columns' => 6,
                    'tab'   =>  'site_assessment_of_the_data_center_location_2'
                )

    Basically the text input just remains visible no matter what option is chosen… Not sure what is causing it though… any way to debug?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Author
    Replies
  • #10835
    Anh Tran
    Keymaster

    Hi,

    After debugging your code, I found that it’s an edge case where the plugin cannot get the correct value of the radio. The problem is when the plugin tries to get the radio inputs, it gets the number input as well. This is because the ID of the number field contains the id of the radio field.

    In this case, please change the id of the number field and the bug will go away.

    #10849
    swartjie
    Participant

    Hey Anh,

    can you please explain further. I am not sure I understand what the problem is? And how to prevent it in the future?

    #10858
    Anh Tran
    Keymaster

    Hi,

    The problem is the plugin doesn’t handle very well the case when a field’s ID contains another field’s ID. In this case the ID of the input contains the ID of the radio field. The plugin make some guests to find the correct elements. And in this case, it gets the wrong elements 🙁

    To prevent this bug, please set the IDs so no one contains another.

    #10860
    swartjie
    Participant

    So what would be an easy way to distinguish between the fields then?
    What if I just place a text in front of each field which would be unique to that field?

    meaning, I do something like substr(md5($field), 0, 5).’__original_field_name’
    That would make the end of the field then unique would it not?

    Or can they contain no parts of eachother? Which is a major bug if you ask me… And not something I should be dealing with really…

    #10861
    Anh Tran
    Keymaster

    The easiest way is just set their IDs like: prefix-text and prefix-radio. Please just don’t make something like field-one and field-one-two.

    I’m working on fixing this bug. Until then, this is the only way to get rid off the bug.

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