Drupal 7 Range: Set two values for a Drupal 7 field

By adam
Fri, 2015-02-27 07:04
Daily Dose of Drupal Episode #195

Share with Others

You ask and you shall receive. That is exactly what happened. Roman, the supporter of the Range Module, asked us to review his module. So that is what we did.

The Range module allows you to add a Drupal 7 field that holds two values or a range. Like similar Drupal fields there are a bunch of various configuration options available. Those include setting label text, minimums, maximums, etc. Also, the Range module provide three different types: integer, float and decimal. Depending on your need you can choose the best type for you. In the video, I cover the positives and negatives to using each type.

Thanks again to Roman for suggesting the Range module. It is a well built module that does the most important thing a module can do. It just works!

If you have any modules you want us to review make sure to use the contact link on the top of the CodeKarate.com site. Thanks.

Hey everybody and welcome to episode number 195 of the Daily Dose of Drupal. I am Adam and today we’re going to be looking at a module suggested by the creator of the module Roman Pasca or on Drupal at Terren and that module he maintains is called range. So what this module does is it’s a pretty simple module that attaches to CCK and allows you to add a field for two different numbers or range.

So I’m going to showcase that in a second and give you a few examples of some used cases that would work with Range Module. But before we do that of course we need to head over to codekarate.com, make sure to check out everything what’s going on there. We just finish up our contest so that if you did enter the contest for our free Drupal Commerce course make sure to check your email. See if you want or get a discount code.

Also on Code Karate make sure to sign up to get the 5 Secrets EBook and also just check out anything you see on the site, love to hear feedback from you so let us know also like Roman did, make sure to tell us any modules you might want us to check out. So let’s get started, so the Range Module, so the Range Module is like I mentioned before, a module that’s going to allow you to do two different fields or two different numbers on the same CCK Field.

So you read through it here, there’s not a lot of set up, but it obviously does have a lot of functionalities actually built into the module. So what…the version is 7.13 here. Obviously it does have an alpha version for Drupal 8 so that’s pretty cool. If you’re looking to get ahead and do a Drupal 8 site you could use this module if needed. So make sure again if you are following the video that you’re using 1.3 otherwise there might be some differences that aren’t going to be covered in this video.

So let’s go ahead and get that module installed, so once we hop over to our site here and we’re going to hop over to our module’s page and make sure we turn the module on, scroll down a little way. You’ll see the module here is going fall under the fieldset called numeric range. There’s nothing co configure on it but make sure you just go ahead and turn it on and save the configuration. So once you have the configuration saved, that’s really all you need to do. Now when you go over to your content types, so under Structure Content Types you can now add this as an option or a field.

So I’m going to go and manage my fields on Houses content type that I created earlier. You see that I already have one in here and I wanted to get one in here so that I can walk you through it and then we can add another one as well. So one used case that I came up with is if you wanted to have potential users or realtors enter in specifics for houses that they might want or want to sell. So for example you could say for Bedrooms, I went in and say okay give me your lowest number of bedrooms and your highest number of bedrooms that you would allow me to have or you would want to sell. So you could enter that, you could also…and we’re going to add another field here for price or bathrooms or things of that nature. Another example would be is via a consulting company and especially in website development and you wanted to give your clients a range of fees.

So you want to say how much are you willing to spend, give us a range from zero to 10 or whatever they think is comfortable for them. So what we’ll do here is let’s add another range field. So we’re going to do Price, and then again on the dropdown here you’ll see three different ones that come along. There’s a decimal, a float range and then into the range. So you’re probably familiar with what a decimal range than a float or excuse me, an integer ranges but you’re probably not too familiar with what a Float Range is and to be honest with you, either was I but when I look it up, basically the main difference is float stores data a lot and takes up a lot less space than a decimal does.

I believe we found out about 20 times less which is pretty significant, but the caveat is it float and it stores it’s done is accurate. Basically, it can change a rounding issue. So for example if you’re using money as a range you don’t want to use Float because you want to be specific about the amount. If you’re using for example height or distance to the sun, you might be able to use a decimal value there it doesn’t have to be as accurate.

So for this example we’re doing Price so I’m just going to do decimal because I want it to be pretty accurate. I don’t care if it takes up a little more storage. And then here we go; so there’s some settings that we can specify the range for decimal and it says Precision. So it’s 200 digits and it’s stored in the database so we can store up to 10 digits, it’s the least end up to 32 is the most. So we’re going to keep it at 10, we’re going to store out full length, anything over that will get dropped and then the number of digits to the right of the decimal, we only want it to be two so keep it there and then we can say what’s our decimal marker and we want it to be a decimal point and not a comma.

And then again this thing will look very similar to any other CCK Field you’ve looked at, there’s a bunch of different configurations. It’s at minimum, it’s maximums, you can do a field prefix which is what I want to do so I’m going to give a dollar sign on that so four. And then again here’s some of the additional ones for your range so you have your from and your two. So you can say…I’m going to change this to say Minimum Price, I’m going to change the two to say Maximum Price. And again you can add prefix and suffixes as well. I will…all other suffix of just, I’m good. And then again if you want default values, again a lot of us will look pretty familiar.

Well let’s go ahead and save our settings and now let’s add in and if you go and add content to our houses we just scroll down here and you’ll see that now we have a minimum price of we can set there and I actually put the suffix right there so that doesn’t look really good so I probably want to get rid of that, but that’s where that would appear. So like I said, a minimum price of 50,000, maximum price of 120,000. And again I can go to decimal values If I wanted, but I won’t for this example. And for bedrooms Let’s say I want 0 to 3, we’re just going to give it title, we’re going to save this and then you’ll see here it adds a decimal value for me so it goes out to that 00. So again this is an as relevance since I’m that larger purchase or probably doesn’t need a decimal value but you’ll see how that works but just again displays it but we give can get rid of those semicolons since it doesn’t really make any sense there but you see how that works. So anyway that’s pretty much the Rang Module, again there’s three different options, there was the decimal which we showed you, the Float and then the Integer. So those are the options to input in and there’s a pile of a lot more examples on those, the ones that I came up with but needless to say it’s not the module you’re going to use every day or on every site, but it definitely is a module that will save you some time if this range issue means to come up. So again guys make sure that you go ahead and think [inaudible - 0:07:43.9] the module and all the other ones. He looks like he’s committed to so that’s awesome. Thanks again for recommending it Roman. Other than that make sure to check out codekarate.com. Again check out our EBook there and also our course and all anything else that might interest you as well. We love to hear feedback as well. So until next time guys, see you.