Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+2 votes
759 views
in Q2A Core by
reopened by

I am trying to use the function 

qa_admin_permit_options($widest, $narrowest, $doconfirms = true, $dopoints = true)

 in my code.

 I tried 

$permitoptions=qa_admin_permit_options(QA_PERMIT_ALL, QA_PERMIT_SUPERS, false, true); 

It works well but when I click on the `registered users with enough points` it doesn't show the field to enter the amount of points.

by
Where are you using it? Is this in plugin options?

1 Answer

+2 votes
by
selected by
 
Best answer

The purpose of the qa_admin_permit_options() function is not to create the visual components but rather to give you the needed options so that you can later create the combobox. It seems you have already created it.

The thing is that the function won't create the input for the points either. So you'll have to create it as well.

If you have already created the input field, then you just need link the combobox to the input. Specifically, you need to define values that toggle the visibility of the input. In the app/format.php file you'll find the qa_set_display_rules() function. The function defines an array of elements that are set their visibility (keys) based on some criteria (values). If the evaluation of the criteria results in true then the element with the ID set in the key will be displayed. Otherwise, hidden.

In admin/admin-default.php you can see this in action by means of the variable $checkboxtodisplay. A partial output of the qa_set_display_rules() looks like this:

qa_display_rule_show('permit_post_q_points', ((opts.option_permit_post_q==106)||(opts.option_permit_post_q==104)||(opts.option_permit_post_q==102)), first);

In short, that sets the id 'permit_post_q_points' to visible only when the value set is equal to 106, 104 or 102.

by
+1
Thank you pupi for your answer. Could you please help me what would be the source to display permit_point here:

    public function admin_form(&$qa_content)
    {
        require_once QA_INCLUDE_DIR.'qa-app-admin.php';
        require_once QA_INCLUDE_DIR.'qa-app-options.php';
        $permitoptions=qa_admin_permit_options(QA_PERMIT_ALL, QA_PERMIT_SUPERS, false, true);
       
       
        $saved=false;

        if (qa_clicked('my_plugin_save_button')) {
            qa_opt('my_plugin_permit', qa_post_text('my_plugin_permit_field'));
            qa_opt('permit_point_needed', qa_post_text('permit_point_needed_field'));
            $saved=true;
        }
        qa_set_display_rules($qa_content, array(
            'permit_point' => ????????????????
        ));
        return array(
            'ok' => $saved ? 'Settings saved' : null,

            'fields' => array(
                array(
                    'label' => 'set permission:',
                    'type' => 'select',
                    'value' => @$permitoptions[qa_opt('my_plugin_permit')],
                    'options' => $permitoptions,
                    'tags' => 'NAME="my_plugin_permit_field" id="my_plugin_permit_field"',
                ),
                array(
                    'id' => 'permit_point',
                    'label' => 'required point:',
                    'type' => 'number',
                    'value' => (int)qa_opt('permit_point_needed'),
                    'suffix' => 'points',
                    'tags' => 'NAME="permit_point_needed_field" id="permit_point_needed_field"',
                ),
            ),

            'buttons' => array(
                array(
                    'label' => 'Save Changes',
                    'tags' => 'NAME="my_plugin_save_button"',
                ),
            ),
        );
    }
by
+1
'my_plugin_permit_field == 106',
...