Jump to content

Fieldtype: Select (AKA Drop Down)


Hani

Recommended Posts

hi, thanks for this nice extension.

what's the best way to output the label instead of value?

wohnung:=Wohnung
einfamilienhaus:=Einfamilienhaus

i don't want to have "wohnung" rendered in this case...

thanks!

Link to comment
Share on other sites

  • 1 month later...

I don't think there is a simple PW way to do this like $page->my_select->title.

This is ugly, but works:

foreach(explode("\n",$page->fields->my_select->select_options) as $option) {
    $valueLabel = explode(':=',$option);
    $value[$valueLabel[0]] = trim($valueLabel[1]);
}

echo $value[$page->my_select];

Damn thanks, I'm trying to do this right now, but wrap this up in a function. Does anyone know how that might be done? I tried this:

function getValueLabel($fieldname) {
	foreach(explode("\n",$page->fields->{$fieldname}->select_options) as $option) {
	    $valueLabel = explode(':=',$option);
	    $value[$valueLabel[0]] = trim($valueLabel[1]);
	}

	return $value[$page->{$fieldname}];
}
echo getValueLabel("currency");

but... yeah that doesn't work... 

Link to comment
Share on other sites

Damn thanks, I'm trying to do this right now, but wrap this up in a function. Does anyone know how that might be done? I tried this:

function getValueLabel($fieldname) {
	foreach(explode("\n",$page->fields->{$fieldname}->select_options) as $option) {
	    $valueLabel = explode(':=',$option);
	    $value[$valueLabel[0]] = trim($valueLabel[1]);
	}

	return $value[$page->{$fieldname}];
}
echo getValueLabel("currency");

but... yeah that doesn't work... 

Most likely the only issue is that PW variables like $page are not available inside functions due to PHP variable scope. If you replace $page with wire('page') is should work just fine.

That said, this is why page fields are a better approach than this module for anything but the very basics (which it is great for!) when it comes to select type fields :)

Link to comment
Share on other sites

  • 2 months later...

Getting:

    Notice: Undefined variable: value in /var/www/web207/html/site/modules/FieldtypeSelect.module on line 65

whenever i store this field to an template from whithin the new "Actions" tab in the field settings.

ProcessWire 2.5.20 dev  

Edit: It happened because i wrote  1:=option1; 2:=option2; .... instead of separating it by Return   

But myabe it would be nice to have a valid error message if you have invalid options.

Link to comment
Share on other sites

What apeisa said, but that error makes me think you've got something incorrect in your Details > Select Options textarea because $value is not being set. The only way I can make that happen is to have more than one ":=" on a row. Of course the module should have a better check on this, but I still think you might have something incorrectly configured.

EDIT - I see you found your error :)

  • Like 1
Link to comment
Share on other sites

As i already said , on first try i copied the    "1:=Poor, 2:=Excellent"  

line from the description on first try. So it was my fault not reading the documentation properly, but still there should be a check. 

@apeisa Thx for the info, i missed that field completely

Link to comment
Share on other sites

  • 3 months 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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...