cyberderf Posted January 9, 2017 Share Posted January 9, 2017 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? Link to comment Share on other sites More sharing options...
fbg13 Posted January 9, 2017 Share Posted January 9, 2017 -1 or have a checkbox that ignores the number of minutes when checked. 1 Link to comment Share on other sites More sharing options...
kixe Posted January 9, 2017 Share Posted January 9, 2017 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) Link to comment Share on other sites More sharing options...
cyberderf Posted January 10, 2017 Author Share Posted January 10, 2017 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? Link to comment Share on other sites More sharing options...
fbg13 Posted January 10, 2017 Share Posted January 10, 2017 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). 1 Link to comment Share on other sites More sharing options...
cyberderf Posted January 10, 2017 Author Share Posted January 10, 2017 @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! Link to comment Share on other sites More sharing options...
cyberderf Posted January 12, 2017 Author Share Posted January 12, 2017 @fbg13 About the checkbox.. is there any way I could link it to the minutes field so there are related? Link to comment Share on other sites More sharing options...
fbg13 Posted January 12, 2017 Share Posted January 12, 2017 @cyberderf Check a field's visibility options under the input tab. 1 Link to comment Share on other sites More sharing options...
cyberderf Posted January 14, 2017 Author Share Posted January 14, 2017 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? Link to comment Share on other sites More sharing options...
fbg13 Posted January 14, 2017 Share Posted January 14, 2017 @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. Link to comment Share on other sites More sharing options...
cyberderf Posted January 20, 2017 Author Share Posted January 20, 2017 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. Link to comment Share on other sites More sharing options...
LostKobrakai Posted January 20, 2017 Share Posted January 20, 2017 There's isn't a one field solution for your problem so yeah, simply hide the integer field if someone selects unlimited. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now