michaeluno / admin-page-framework

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

Multiple strFieldID with same value #59

Closed soderlind closed 10 years ago

soderlind commented 10 years ago

This doesn't work since strFieldID is the same for both sections (only the last will appear) , but I feel I should be able to use the same strFieldID value as long as they are in different sections (they are logically different since they are children of different sections).

Just my 2c :)

<?php
        $this->setRootMenuPage( 'Config'); 
        $this->addSubMenuPage(    
            'Production',
            'prod',
            'tools'
        );
        $this->addSettingSections(
            array(
                'strSectionID'    => 'conf_prod',
                'strPageSlug'    => 'prod',
                'strTitle'    => 'Production'
            )
        );        
        $this->addSettingFields(
            array(
                'strFieldID' => 'version',
                'strSectionID' => 'conf_prod',
                'strTitle' => 'Versionsnumber',    
                'strType' => 'text'
            )
        );
        $this->addSubMenuPage(    
            'Beta',
            'beta',
            'tools'
        );     
        $this->addSettingSections(
            array(
                'strSectionID'    => 'conf_beta',
                'strPageSlug'    => 'beta',
                'strTitle'    => 'Beta'
            )
        );        
        $this->addSettingFields(
            array(
                'strFieldID' => 'version',
                'strSectionID' => 'conf_beta',
                'strTitle' => 'Versionsnumber',    
                'strType' => 'text'
            )
        );
?>
michaeluno commented 10 years ago

In v3, the section dimension was dropped from the saved option array structure ( https://github.com/michaeluno/admin-page-framework/issues/45 ) so even if multiple same filed IDs are allowed, only one will be saved. Based on that change, I've made some other changes in the field output structure that uses some element tag IDs without the section ID but with the field ID (on contrary to v2, which determines each tag ID by section ID + field ID).

Apart from that, there is the validation_{class name}_{field ID} hook and validation_{class name}_{input ID} hook for the submit field type so a single field ID in one extended class is allowed. The input ID is determined by the field ID and the index.

When I introduced the former hook, I thought of making it validation_{class name}_{section ID}_{field ID} or validation_{section ID}_{field ID} but thought it not consistent with meta box classes; meta box fields don't have sections. Recently taxonomy fields have been introduced in v3 beta and they don't have sections either. The idea of user profile fields has been suggested ( https://github.com/michaeluno/admin-page-framework/issues/56 ) and it seems they use sections on the other hand.

So we need to think carefully with different aspects. At the moment, I'm not leaning towards it. But I see your point.

michaeluno commented 10 years ago

I'm opening this proposal as we are going to have the section dimension in the option array structure back.

michaeluno commented 10 years ago

In v3 beta, this has become possible.

Sample test plugin: https://gist.github.com/michaeluno/8996361