Custom Fields
Re-Envisioned
Support General Validation not working on FIle or File Advanced Field

  • Creator
    Topic
  • #3521
    Webbio
    Participant

    Metabox Version 4.8.7
    I want File field required but the validation is only working of INPUT fields not for File Type or File Upload Field http://i.imgur.com/DP5Wbnq.png

    
        $meta_boxes[] = array(
            // Meta box id, UNIQUE per meta box. Optional since 4.1.5
            'id'         => 'standard',
            // Meta box title - Will appear at the drag and drop handle bar. Required.
            'title'      => esc_html__( 'Standard Fields', 'your-prefix' ),
            // Post types, accept custom post types as well - DEFAULT is 'post'. Can be array (multiple post types) or string (1 post type). Optional.
            'post_types' => array( 'post', 'page' ),
            // Where the meta box appear: normal (default), advanced, side. Optional.
            'context'    => 'normal',
            // Order of meta box: high (default), low. Optional.
            'priority'   => 'high',
            // Auto save: true, false (default). Optional.
            'autosave'   => true,
            // List of meta fields
            'fields'     => array(
                array(
                    'name' => esc_html__( 'Image', 'your-prefix' ),
                    'id'   => "{$oyeprefix}file1",
                    'type' => 'file',
                    'max_file_uploads' => 1
                ),
             
            ),
            'validation' => array(
                'rules'    => array(
                    "{$oyeprefix}file1" => array(
                        'required'  => true,
                    ),
                ),
                // optional override of default jquery.validate messages
                'messages' => array(
                    "{$oyeprefix}file1" => array(
                        'required'  => esc_html__( 'File is required', 'your-prefix' ),
                    ),
                ),
            ),
        );
    
Viewing 1 replies (of 1 total)
  • Author
    Replies
  • #3525
    Anh Tran
    Keymaster

    Sorry, the validation hasn’t worked for media fields for now :(. We use complicated JS to handle upload/insert files and generate the HTML dynamically. That makes the validation JS not work 🙁

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