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...
  • 8 years later...

I use the Fieldtype: Select (AKA Drop Down) a lot. And I'd be happy to switch to the Fieldtypeoptions, but  I need something that allows me to create a variable, and show a human name to the user ...

Something like this:

left:=left
right:=right

The FieldtypeOptions creates this:

1:left
2:right

I use them for a variety of things like choosing image effects on photos...

uk-background-blend-color-dodge:=Color Dodge
uk-background-blend-color-burn:=Color Burn
uk-background-blend-hard-light:=Hard Light

where I can add to the code:  {$item->imagefx} on an image. 

What is the workaround for this?

 

 

Link to comment
Share on other sites

Posted (edited)
55 minutes ago, bernhard said:

1=left|Left aligned image
2=right|Right aligned image

 

Okay, never underestimate the power of anxiety...

this seems to work: {$page->fieldName->value}

 

 

Edited by hollyvalero
I think I got it...
Link to comment
Share on other sites

Might also be worth mentioning, it looks like you are trying to set the crop point of an image. Do you know about focus points on images with newer versions of ProcessWire? There would be no need for a dropdown then. 

  • Like 1
Link to comment
Share on other sites

1 minute ago, cb2004 said:

Do you know about focus points on images with newer versions of ProcessWire? 

* Oh, yeah... I'm using these for things like moving a photo from the left side of a block to a right side, adding padding of various amounts, etc.

 

Link to comment
Share on other sites

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...