Jump to content

Select Options Field Type Bug


obesegiraffe
 Share

Recommended Posts

Hi all, first time poster on the forums but long-time user of Processwire. I couldn't find this exact problem in the forums and I'm hoping it's just something simple I'm missing (first day back from vacation so I am a little brain dead). 

I have a Select Options Field Type where the client can choose an array of numbers. If nothing is chosen, nothing is outputted onto the page. This works for most pages using this specific template. However, on just one page where I have the field set to blank, I am finding it is still outputting "0", when it actually shouldn't be outputting anything. My code:

<?php if($page->percent_leased->has('id!=0')){ ?> 
	<h2><?=$page->percent_leased->title?>% Leased</h2> 
<?php } ?>

On this specific page, it is outputting "0% Leased". It's also doing something kind of weird in the database under the percent_leased field type. It's repeating the same ID of the specific problem page twice (page ID 1086) when I set it to blank. It works fine if I actually choose a number and the duplicate goes away. I've never really delved deep into the databases so maybe this is normal? 

595c03aabb9e2_ScreenShot2017-07-04at3_07_34PM.png.cc71c310711d579880463f092277a649.png

The weird thing is is that this is working fine on all other pages using this template. It's just this one page acting weird. FWIW, this particular site is running version 2.6.1. 

Thanks for reading!

Link to comment
Share on other sites

Welcome @obesegiraffe,

Not sure that this could be the cause of the problem, but the way you are checking if the Options field is populated looks a bit unusual to me. Does it make a difference if you use count() instead?

<?php if(count($page->percent_leased)){ ?>
	<h2><?=$page->percent_leased->title?>% Leased</h2>
<?php } ?>

The database table looks like what you get if your Options field is set to one of the "Multiple values" inputfields. If you have changed the input type from Multiple to Single at some point then you would need to save each of the pages in admin that had any multiple values saved for it in order to trigger the value to update.

  • Like 1
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
 Share

×
×
  • Create New...