Custom Fields
Support Meta Box Conditional Logic Conditional Logic with Validation

This topic contains 1 reply, has 2 voices, and was last updated by  Anh Tran 3 weeks, 1 day ago.

  • Creator
  • #16190


    I’m having an issue with a my post updating when I have a required field that is hidden Conditional Logic. The field shows when a choice is selected in dropdown. How can I get this to work?

    Here is how it works:
    I have a required select_advanced field called Status with 3 options: Available, Under Contract and Sold. I have another required field called Sold Price and only shows if “Sold” is selected in the Status field. Since my Sold Price field is required and hidden, I can’t update my post without having validation issues.


    // Start Fields
    'fields' => array(
    // SELECT ADVANCED - Status
      array (
        'id' => $prefix . 'status',
        'name'          => 'Status',
        'type'          => 'select_advanced',
        'placeholder'   => 'Select Status',
        'options'       => array(
          'Available'     => 'Available',
          'UnderContract' => 'Under Contract',
          'Sold'          => 'Sold',
    // TEXT - Sold Price
      array (
        'id'      => $prefix . 'sold_price',
        'type'    => 'text',
        'name'    => 'Sold Price',
        'prepend' => '$',
        'hidden'  => array( $prefix . 'status', '!=', 'Sold' )
    ), // End Fields
    // Start Validation
    'validation' => array(
      'rules'  => array(
        $prefix . 'staus' => array(
          'required'  => true,
        $prefix . 'sold_price' => array(
          'required'  => true,
    ) // End Validation
Viewing 1 replies (of 1 total)
  • Author
  • #16237

    Anh Tran


    This is a common problem. Logically, when a field is not needed (hidden), it can’t be required. In this case it’s the price field. Unfortunately, there’s no built-in solution for toggling validation rules based field visibility.

Viewing 1 replies (of 1 total)

You must be logged in to reply to this topic.