Custom Fields
Support Meta Box Conditional Logic Conditional Logic with Validation

  • 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 2 replies - 1 through 2 (of 2 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.


    I think it should be possible to exclude hidden inputs using the ignore options of jQuery Validation.

    I've tested this by changing:

    ignore: ':not([class|="rwmb"])',

    in wp-content\plugins\meta-box\js\validate.js to

    ignore: ':not([class|="rwmb"]), [data-visible="hidden"] .rwmb-input input',

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