Jump to content

Recommended Posts

Posted

I am wondering what strategy I should choose for building a field which can have unlimited value and then should be correctly sorted with a filter on frontend side.

This is not my concrete case, but i'ts a similar example :
Suppose a cellular phone plan. The phone plan have a template with a field called 'Minutes included with the plan'. The number of minute can from 0 to unlimited.

How would you handle the unlimited value?

Posted

There is always a limit for numeric values using mysql databases.
The Processwire builtin FieldtypeInteger for example can store values between 0 and 4294967295.
Creating a custom Fieldtype may store integer values until 18446744073709551615 if you use Data type BIGINT.

(note: assuming you are talking about integer values. There are also limits for text and other stuff)

 

Posted
7 hours ago, fbg13 said:

-1 or have a checkbox that ignores the number of minutes when checked.

What do you mean by having a checkbox that ignores the number of minutes when checked?

Will entering -1 for a numeric field gives me the ability to sort it as the biggest number possible?

 

Posted
1 hour ago, cyberderf said:

What do you mean by having a checkbox that ignores the number of minutes when checked?

I mean you have an extra checkbox field in your template and when you give someone the unlimited minutes plan you check the checkbox. This adds another step in your code though, as you have to verify if the checkbox is checked for every plan.

// isUnlimited is the checkbox fields name
// numberOfMinutes is the field that holds the number of minutes
if($page->isUnlimited == 1) {
	$plan = "unlimited";
} else {
	$plan = $page->numberOfMinutes;
}
// so if the checkbox is checked the plan becomes unlimited regardless of what the value of numberOfMinutes is

 

1 hour ago, cyberderf said:

Will entering -1 for a numeric field gives me the ability to sort it as the biggest number possible?

Might be possible with a custom sort function, but what you could also do is have one variable for -1 and one for the rest

$plans = "";
foreach($page->numberOfMinutes as $minutes) {
	if($minutes == -1) {
		$plan = "unlimited";
		continue;
	}
	$plans .= "{$minutes} <br>";
}

echo $plans . $plan;
// or
echo $plan . $plans;

Or you could simply add a huge number for the unlimited plan like 999999 (that's about 694 days in minutes).

  • Like 1
Posted

@fbg13 Great explanation!

If I understand you well, both strategy will leave me extra code on frontend.

So I think I prefer the extra checkbox more, because I like the fact that it's clear in the backend for end users that the plan is unlimited (and not -1 min). To prevent error I could probaly add a validation in PCW backend so checking the Unlimited min. field would make the user unable to enter something in the Minutes field.

Cheers!

Posted
On 12/01/2017 at 0:22 PM, fbg13 said:

@cyberderf Check a field's visibility options under the input tab.

I am not sure I get it..   You mean make the integer value field invisible if the the unlimited checkbox is checked?

 

Posted
On 14/01/2017 at 0:38 PM, fbg13 said:

@cyberderf I mean look at the available options and use the one that fits, if none fits then explain in more detail what and when you want to happen.

I want to have both things linked. Because in the backend it would be simplier for entering the data.

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