michaeluno / admin-page-framework

Facilitates WordPress plugin and theme development.
http://admin-page-framework.michaeluno.jp/
Other
339 stars 71 forks source link

question: Revealer Field - reveal more than one field #89

Closed patrickf0 closed 10 years ago

patrickf0 commented 10 years ago

Hi there,

is it possible to reveal more than one field when using the revealer custom field type?

michaeluno commented 10 years ago

It requires a bit of customization and some small breaking changes.

I've realized that revealing sub-fields is not practical as they inherit settings of the main field that requires sub-fields to override the value option and there is no way to override with the stored value at the moment. So I'm going to remove the example field for revealing sub-fields.

patrickf0 commented 10 years ago

Maybe it is possible to extend the revelation in section IDs?

michaeluno commented 10 years ago

I updated the 3.0.3b branch which includes a small breaking change with the revealer field type in return for the ability to reveal more than one elements.

You can use it like this

'label' => array(
    '#element_id_a, #element_id_b' => 'Element A and B',
    '.element_class_a' => 'Elements Class A',
)

The array keys of the label option serve as the selector which will be given to the jQuery method. So you can even use a class selector instead of an ID to reveal a group of elements.

        $this->addSettingFields(
            array(
                'field_id'  =>  'revealer_field_by_id',
                'section_id'    =>  'revealer',
                'type'  =>  'revealer',         
                'title' =>  __( 'Reveal Hidden Fields' ),
                'value' =>  'undefined',    // always set the 'Select a Field' label.
                'label' =>  array(  // the keys represent the selector to reveal, in this case, their tag id : #fieldrow-{field id}
                    'undefined' => __( '-- Select a Field --', 'admin-page-framework-demo' ),       
                    '#fieldrow-revealer_revealer_field_option_a'    => __( 'Option A', 'admin-page-framework-demo' ),       
                    '#fieldrow-revealer_revealer_field_option_b, #fieldrow-revealer_revealer_field_option_c'    => __( 'Option B and C', 'admin-page-framework-demo' ),
                ),
                'description'   =>  __( 'Specify the selectors to reveal in the label keys in the field definition array.', 'admin-page-framework-demo' ),
            ),

As for the question to reveal an entire section, each section element has an ID of section-{section ID}__{index}. So you may use that. However, you need to have a script to hide them when the page loads.

michaeluno commented 10 years ago

I've submitted v3.0.3, which includes this change. So I'm going to close this topic.

To reveal sections, as I wrote in the previous reply, the section HTML elements need to be hidden first. At the moment, you need to do that by your self with a JavaScript script. Maybe the hidden option can be added to the section definition array. If you need it, you can post a new issue suggesting it.