Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vValue option does not work correctly with selecter setting field type #9

Closed
PBullock opened this issue Oct 15, 2013 · 3 comments
Closed
Labels

Comments

@PBullock
Copy link

Can be quickly reproduced by adding 'vValue' array to the selecter demo in "admin-page-framework-demo.php".

$this->addSettingFields(
array(
'strFieldID' => 'test_drpdwn_2',
'strSectionID' => 'test_fields',
'strTitle' => 'Options - 2',
'strDescription' => 'some more options but with vValue set',
'strType' => 'select', // Single Drop-down List
'vDefault'=> 2,
'vValue' => array ( 'first option', 2 , 'etc option' ),
'vLabel' => array ( 'first option' , 'next option' , 'etc option' ),
)
);

Adding the vValue optional array causes the 'selected="selected"' option tag in the output option field to remain fixed on the value=0 option, the vValue field does not seem to have taken effect either. Any calls to this value result in 0 until the vValue field is removed. I have tried using intergers, strings and different orders.

@michaeluno
Copy link
Owner

This is the intended behavior and it's not a bug. For the select field type, you need to specify vLabel's key name in the vValue key as you did with the vDefault key.

Try changing it to:

'vValue' => 1,

This would select the second option item as PHP arrays are zero-base.

Optionally, you may use an associative array for the vLabel field element so that it will be clearer what element you would need to highlight(select) with the vValue field element.

'vLabel' => array(
    'first' => 'first option',
   'second' => 'second option',
    'third' => 'third option',
),
'vValue' => 'second',

@PBullock
Copy link
Author

Thanks for taking the time to show that. I hadn't looked at the result of
your example properly and just spent a fair amount of time trying to
explain that it wasn't working >.<
Clearly I just didn't understand the code or the route my issue, which was
obviously not reading deep enough and fully understanding what was written
(and the functioning of arrays).

Again, many thanks, although i spent some time on this you have still have
saved me probably years overall!

Pete

On Wed, Oct 16, 2013 at 2:10 AM, michaeluno notifications@github.comwrote:

This is the intended behavior and it's not a bug. For the select field
type, you need to specify vLabel's key name in the vValue key as you did
with the vDefault key.

Try changing it to:

'vValue' => 1,

This would select the second option item as PHP arrays are zero-base.

Optionally, you may use an associative array for the vLabel field element
so that it will be clearer what element you would need to highlight(select)
with the vValue field element.

'vLabel' => array(
'first' => 'first option',
'second' => 'second option',
'third' => 'third option',
),
'vValue' => 'second',


Reply to this email directly or view it on GitHubhttps://github.com//issues/9#issuecomment-26383497
.

@michaeluno
Copy link
Owner

Not a problem.

It is appreciated that you took the time to explain your issue and presented it in detail so that it gives me a clue what is confusing for the users.

This helps when a new feature gets implemented. I'll be more careful to design the code and write the documentation. I would avoid code structures that is told it could cause confusion.

If you encounter a confusing part in the code or the documentation, feel free to submit a better one. This library is merely a work of an individual whose native language is not English. Contributions are always appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants