Viewing 5 reply threads
  • Author
    Posts
    • #3253
      hirschbrat
      Member

      Hello,

      is there any hook that I can use to validate multiple custom fields at the same time?
      E.g. I have a meta-box with three dates and want to validate the dates as follows:
      date1 < date2 < date3
      AND date2-date1 > 5 days
      AND date3-date2 > 5 days

    • #3254
      Kevin
      Keymaster

      Actually yes. Can you post your meta-box code? This way we can show you a relevant example.

      Thanks,

      Kevin

    • #3255
      hirschbrat
      Member

      Hello Kevin,

      this is my meta-box code. I want to validate the three fields fvb_shipping_date, fvb_event_date and fvb_return_date.

      /*
      Title: Termine
      Description: Bestellte Produkte
      Post Type: fvb_order
      Capability: manage_options
      Context: side
      Priority: low
      Order: 1
      Locked: false
      Collapse: false
      Meta box: true
      */
      
      piklist('field', array(
          'type' => 'datepicker'
          ,'field' => 'fvb_event_date'
          ,'label' => __('Veranstaltungsdatum', 'fvb_de')
          ,'options' => array(
              'dateFormat' => 'yy-mm-dd'
              ,'firstDay' => '1'
              ,'minDate' => '0'
          )
          ,'required' => true
          ,'on_post_status' => array(
              'value' => 'reserved--closed'
          )
      ));
      piklist('field', array(
          'type' => 'number'
          ,'field' => 'fvb_event_period'
          ,'label' => __('Dauer', 'fvb_de')
          ,'description' => 'Tag(e)'
          ,'value' => 1
          ,'on_post_status' => array(
              'value' => 'reserved--closed'
          )
          ,'validate' => array(
              array(
                  'type' => 'limit'
                  ,'options' => array(
                      'min' => 1
                  )
                  ,'message' => 'Min 1 day.'
              )
          )
      ));
      
      piklist('field', array(
          'type' => 'datepicker'
          ,'field' => 'fvb_shipping_date'
          ,'label' => __('Versand', 'fvb_de')
          ,'options' => array(
              'dateFormat' => 'yy-mm-dd'
              ,'firstDay' => '1'
              ,'minDate' => '0'
          )
          ,'required' => true
          ,'on_post_status' => array(
              'value' => 'reserved--closed'
          )
      ));
      piklist('field', array(
          'type' => 'datepicker'
          ,'field' => 'fvb_return_date'
          ,'label' => __('Retour', 'fvb_de')
          ,'options' => array(
              'dateFormat' => 'yy-mm-dd'
              ,'firstDay' => '1'
              ,'minDate' => '0'
          )
          ,'required' => true
          ,'on_post_status' => array(
              'value' => 'reserved--closed'
          )
      ));
    • #3263
      Kevin
      Keymaster

      @hirschbrat-

      I spoke a little too soon, but not by much. We are very close to our next release and this version has a few upgrades to validation allowing you to inspect other fields in your callback. Email us at [email protected] and we will send you a snippet with a version of the beta this week.

      Thanks,

      Kevin

    • #3269
      Jason
      Keymaster

      Greetings! Like Kevin said, in the next version you can view all the fields and validate accordingly. Presently, it’s possible to do this if multiple fields belong to a single group. For an example of this check out the ‘date-range’ validation in PiklistHelper: https://github.com/JasonTheAdams/PiklistHelper/blob/master/PiklistHelper.php#L231

    • #3350
      Steve
      Keymaster

      @hirschbrat– The beta just got emailed to you. Let us know if you still have issues.

Viewing 5 reply threads
  • You must be logged in to reply to this topic.