Jump to content

Recommended Posts

Posted

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 ? 

Posted

Select will return a string. Select Multiple will return an array.

The label or title is part of the field definition, not the stored value for that field for the selected row.

Does that make sense?

  • 9 months later...
Posted

Hi there, we have the same problem as Sonja.

Adrians last hint with the getLabel()-method shows the label of the select field itself, but not the label or title of the selected option. Are there some news concerning this topic?

Posted

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

  • 5 months later...
Posted

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
  • 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
×
×
  • Create New...