Can I access Dropdown list option text?
Permalink Browser Info Environment
Hi Jordan
I created a dropdown list with 3 options that I want to output depending on what was chosen. Can you tell me if there is an easy way to do that?
e.g.
Options:
- Height
- Length
- Depth
If someone chooses the first option, I just want to out the exact option text "Height".
By default, view.php has:
etc... for each option
I don't really want to have to retype the option text for each item, so was hoping I could just use a variable like: $field_1_select_option
Is a variable like this available?
Thank you!
I created a dropdown list with 3 options that I want to output depending on what was chosen. Can you tell me if there is an easy way to do that?
e.g.
Options:
- Height
- Length
- Depth
If someone chooses the first option, I just want to out the exact option text "Height".
By default, view.php has:
<?php if ($field_1_select_value == 1): ?> <!-- ENTER MARKUP HERE FOR FIELD "Unit 1" : CHOICE "Height" --> <?php endif; ?>
etc... for each option
I don't really want to have to retype the option text for each item, so was hoping I could just use a variable like: $field_1_select_option
Is a variable like this available?
Thank you!
Type: | Discussion |
---|---|
Status: | New |
Hi,
I think the method you came up with is just fine. The dropdown field is not very robust -- it's goal was just to allow the user to choose from a few different design options, not to actually serve as a way to output certain data.
One thing you might want to do though to reduce code duplication (so if you change the list in the future you won't accidentally forget to change it in one place but not the other) is add a new function to the controller that returns that array. Then in edit.php and view.php call the function to get the array.
For example, the controller function would look like this:
Then in the edit and view.php file you can do this:
Hope that helps!
-Jordan
I think the method you came up with is just fine. The dropdown field is not very robust -- it's goal was just to allow the user to choose from a few different design options, not to actually serve as a way to output certain data.
One thing you might want to do though to reduce code duplication (so if you change the list in the future you won't accidentally forget to change it in one place but not the other) is add a new function to the controller that returns that array. Then in edit.php and view.php call the function to get the array.
For example, the controller function would look like this:
public function getUnitOptions() { return array( '0' = '--Choose One--', '1' => 'Height', '2' => 'Length', '3' => 'Width', ); }
Then in the edit and view.php file you can do this:
$unit_options = $controller->getUnitOptions();
Hope that helps!
-Jordan
Thanks Jordan! I will do that!
I saw your post about Designer Content Pro - I look forward to hearing more about the features. The repeating items sounds handy as I have used your block for quite of few lists of items (products, categories, testimonials) and I've had to kind of compromise my ideal HTML code (e.g. when I've wanted to us UL for lists) and do crazy things with stacks and layouts to make the content reusable.
Cheers!
I saw your post about Designer Content Pro - I look forward to hearing more about the features. The repeating items sounds handy as I have used your block for quite of few lists of items (products, categories, testimonials) and I've had to kind of compromise my ideal HTML code (e.g. when I've wanted to us UL for lists) and do crazy things with stacks and layouts to make the content reusable.
Cheers!
I noticed this code in the edit.php:
So I used this code to create option lists in my view.php file:
then later in my HTML code:
It works... but I was hoping there might be a better way to do this :)
Thanks
- Mal