Jump to content

Select field inside a profields Table


Sonia Margollé
 Share

Recommended Posts

I have a problem and I don't understand. I have a profield table with different fields and a select field.
I did like it's instructed and put "value=label".

But when I'm trying to output the select field with var_dump (to debug),  it's indicated that the field is a string that contains the value.
Why is it a string ?  when I try  myselectfield->value  or label or title I have an error saying I'm trying to get a property on a non-object ...

Anyone ? 

Link to comment
Share on other sites

  • 9 months later...

I'd need to look into this a little more to figure out how to get the label if you have defined a manual value, but if you don't define a value, then it automatically returns the label:

image.png.1bb4d35f41fbd319d2a064904a99bebc.png

Would this work for you, or do you need to specify a value for each option?

Got to sleep here, but this shows that you could parse this yourself by grabbing the field's colnoptions setting. Not exactly elegant, but it'll work..

image.png.53ae427f7a957144456b42425c8db797.png

Link to comment
Share on other sites

  • 5 months later...

I figured this out, after running into this issue myself and digging into the FieldtypeTable class...definitely not intuitive though.  Ideally a title or label property or method would just be exposed here.

$field = $fields->get('table_field'); // Field
$columnName = 'column'; // Column name in table
$optionValue = 'my_option'; // Option value
$optionTitle = $field->type->getSelectColumnOptions($field, $columnName)[$optionValue]; // Returns array of value => label
echo $optionTitle;

 

  • Like 1
Link to comment
Share on other sites

  • 2 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...