Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
Notice that we have a space for name, email. We have a little bit of validation going on here now, because it's saying, "Hey, email is required." Location, Skype Name, and we have this little section that says, "What is the best way to reach you?" and we don't have anything there. We are going to give some radio buttons for them to select and I would like those radio buttons to validate as well. So we'll go ahead and use the new Spry Validation Radio Group widget. Alright, so go ahead and place your cursor right after the sentence, What is the best way to reach you, and we are going to insert a line break. For those of you that might not be familiar with how to do that, just Shift+Enter and that will give us a line break and it will move us down to the next line.
Now, I am going to go to my Insert panel and I am going to go to my Spry Objects and in my Spry Objects in the middle of the section here, we have some of our validation widgets> We have the Spry Validation, we have the Spry Validation Select, Password, Validation Confirm, Radio Group, so we have some new ones here. And I want to choose the Spry Validation Radio Group so I am going to click on that to add this. Now the first thing that it is going to ask me is what do you want inside this Radio Group. So we're not really dealing with any validation stuff just yet. I am going to name this rgContact to give our Radio Group a name and it comes automatically with two labels.
So let's go ahead and fill out the first two. I am going to type in Email as the first label and for the value, I am going to give it email. And notice I've used a capital E for the label and then a lowercase e for the value. I'll hit tab to the next one and I'll type in Skype and then I will just do a lowercase skype. Anybody who's used radio button before, knows what's happening here. The label is what's actually going to show up on the page, and the value is what's going to be returned with the form. We need one more so I am going to click my plus button here to add another one, another radio button and this one is going to be Yelling and it's value will be yell.
My other option is to insert this with line breaks or to use table markup. I am going to remove all the table markup from my page, so I just want to use line breaks and I'll click OK. There is our new radio group, Email, Skype and Yelling. Now, if you click on these guys individually, you can make any changes that you are used to making. So this isn't special in anyway other than the fact that you are just placing content on the page. You can still write your styles for this, you can still isolate it and do whatever you want to. Let's take a look at how we deal with the Validation widget itself. You'll notice a blue outline and a blue tab, the Spry Radio Group tab and if I click on that tab, my Properties inspector now gives me the Spry Validation Widget properties, so I can go ahead and change these.
Now the first thing I'm going to change is how and when this validates. By default, any widget is validated on the Submit of the form. Well you can change that as well. We're going to add both Blur and Change to this so that it validates whenever somebody changes the value or when they switch focus from this to something else which is perfect. Right now, we are looking at our Initial preview state, but if I grab that pulldown menu, I can also click on the Required to see what this is going to look like when it's giving them, hey, this is required. And the default text that says "Please make a selection." I am going to highlight that and change it to give it something that's a little bit more in-line with the attitude of our site. So, I am going to type in, Hey... we REALLY need an answer! And that deserves an exclamation point.
So we are just changing that. You don't have to use the default text. You can use whatever you want to, it doesn't really matter. So now we've got an invalid state as well. Let's go back to our Spry Validation widget properties. Go and click back on that blue tab and we notice over here as well that we have an Empty and an Invalid Value. I want to talk about those for just a moment. If there is one of the items that you want it to validate as if that item had been left blank, you would use an Empty value. We don't really want that but we do have a value for this particular part of form that's invalid.
The Yelling one, for example. We don't really care if somebody chooses Yelling or not. So I am going to type in yell for my Invalid Value and now in addition to our preview states of Initial/Required, we have Invalid as well. And you can see that if somebody chooses Yelling, it will now tell them to please select a valid value. Well I want to give them a little bit more of an explanation for that. So I am going to highlight this and I am going to type in, Dude, we were just kidding. Email or Skype? That way if somebody actually tells us that yelling is the best way to reach them, we can respond them by saying we were just kidding.
So now let's go ahead and save the file. Now, as soon as we save it, it's going to add a couple of files to our site. SpryValidationRadio.css and SpryValidationRadio.js. If you already have a SpryAssets directory, it will add it to an existing one and if you don't have one, it will create it for you. So I am going to go ahead and click OK and I can see, if I refresh my site, that they've added those. So after doing that, I am going to go ahead and preview this on my browser and if I just scroll down and submit a form, if I scroll back up to that area, you can see it says, "Hey, we really need an answer." Well if I start clicking on these answers that goes away.
But if I click on Yelling, notice again that it says, "Dude, we were just kidding. Email or Skype?" You can see that any sort of validation text here is red and is appearing in sort of a red outlined box. Well that's being controlled through the CSS. If you want to modify that, you could simply go into the external Spry Validation CSS file and change that, and make it look anyway that you want. You can add background graphics to it or take off the outline. It's really up to you. Whatever you'd would like to do. As you can see, the Spry Radio Group Validation widget offers us a very quick and easy way to add robust client-side validation to radio button groups.
Get unlimited access to all courses for just $25/month.Become a member
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.