Forms

Form Input Variants and Validation in Framer

Form Input Variants and Validation in Framer

Form Input Variants and Validation in Framer

Joseph

·

7:52

·

18K views

·

About this lesson

We’ve looked at how to add a simple focus effect for an input on the properties — but that’s just scratching the surface. Let’s take a look at how we can take input states and validation to the next level using components.

We’ll have an input with a placeholder as the default state…

Then when we click, we’ll enter a focused state — and the label will move up above the input….

Then after we type something and click away, we want to have a defocus, or “blur” state, where the styling is like the default state — but the label remains up and above the input….

Then finally, we want an invalid state in case what’s typed in the input is not a valid email address — But also to re-validate the text once it’s fixed.

Let’s build it.

https://www.youtube.com/watch?v=qN9giCMK6Zo&t=0s Intro

https://www.youtube.com/watch?v=qN9giCMK6Zo&t=5s What we’re building: input states and validation

https://www.youtube.com/watch?v=qN9giCMK6Zo&t=16s Setting up the form and default state styling

https://www.youtube.com/watch?v=qN9giCMK6Zo&t=27s Adjusting layout and label positioning

https://www.youtube.com/watch?v=qN9giCMK6Zo&t=46s Creating the focus variant

https://www.youtube.com/watch?v=qN9giCMK6Zo&t=62s Adding blur and invalid variants

https://www.youtube.com/watch?v=qN9giCMK6Zo&t=78s Styling borders for smooth animations

https://www.youtube.com/watch?v=qN9giCMK6Zo&t=94s Adding focus interactions

https://www.youtube.com/watch?v=qN9giCMK6Zo&t=109s Why we need a blur state

https://www.youtube.com/watch?v=qN9giCMK6Zo&t=140s Handling empty vs filled blur logic

https://www.youtube.com/watch?v=qN9giCMK6Zo&t=170s Adding validation for invalid input

https://www.youtube.com/watch?v=qN9giCMK6Zo&t=205s Fixing the invalid state with revalidation

https://www.youtube.com/watch?v=qN9giCMK6Zo&t=258s Wrap up

🌞 Start for free: https://framer.link/yt

📚 Learn more at: https://framer.link/yt-academy

💎 Join the Community: https://framer.link/yt-community

🎉 Follow on X: https://framer.link/yt-x

0:00we've looked at how to add a simple0:01Focus effect for an input on the0:03properties panel but that's just0:05scratching the surface let's take a look0:07at how we can take input States and0:09validation to the next level using0:13[Music]0:15components in my project I've got a0:17simple form here with a text input for0:19an email address and a submit button but0:22let's take a quick look at what we're0:23trying to accomplish here we want to end0:25up with an input with a placeholder as0:28the default state then when we click0:30we'll enter a focus State and the label0:32will move up above the input then after0:35we type something and click away we want0:38to have a defocus or blur state where0:40the styling is like the default state0:43but the label remains up above the input0:46then finally we want an invalid state in0:48case what's typed in the input is not a0:51valid email address but also to0:53revalidate the text once it's fixed0:56let's build it back in the project I'll0:58start by selecting the entire label1:01frame right clicking and choosing create1:05component I'm going to start by making a1:07few changes to the primary variant1:09before we create the others let's start1:12by giving it a more descriptive name1:13like1:15default now I'm going to change the1:17height of this Frame to fixed to1:20preserve this extra space up here when1:22we move the label1:23around then I'll set the email label to1:26Absolute positioning so we can move it1:28around freely you'll notice the input1:30jumped up to the top that's because the1:32parent frame is a vertical stack and the1:34input's position type is relative1:37meaning it follows the flow of the stack1:39that it's in we could set the input to1:42Absolute positioning or have it align1:44with the bottom of the stack it's in by1:46changing the stack to distribute from1:48end rather than start which for a1:50vertical stack means from bottom rather1:53than top that's better next I'm going to1:56delete the placeholder text for the1:57input1:59and instead move the label text box down2:02onto the input to behave as our2:04placeholder that way we can animate the2:06label moving back and forth I'll2:09increase the font size slightly to2:1114 and make sure the text box is inset2:14evenly on the top bottom and left2:17another thing worth noting is that my2:19input field has no Focus effect we're2:21going to create a variant for the focus2:23State instead and I think we're all good2:26for our primary variant I'll click to2:28add our second variant and rename this2:31one2:32Focus now in the focus State the user2:35will have just clicked or tapped into2:37the field to type something so we'll2:39need to move the placeholder text back2:41up and out of the2:42way and I'll bring the size back down to2:4512 pixels while we're at2:46it before I continue on with styling2:49let's actually pause here for a moment2:50the layout of this Focus state is2:53actually exactly the same as the layout2:54I want for our blur and invalid States2:57so while we're here we might as well2:59create create a couple more3:01variants and name one of them3:04blur and the other one3:07invalid now we can style each one since3:10a couple of variants are going to have3:11borders around the inputs we can make3:13our animations extra Smooth by making3:16sure that every variant has a border3:19that way the property itself isn't3:20snapping on and off so I'll select the3:23input of the primary variant add a3:27border increase the width to two3:30pixels and for the color I'll drag the3:33alpha all the way down to3:350% now for the focus state I'm just3:38going to select the3:39input select the Border3:42property and change the color to3:45Blue and similarly for the invalid State3:48I'll select the input select border3:50property and make it3:53red and I'll go one step further with3:55this one and select the text and make3:58that red as well to help grab the users4:00attention great now we have our four4:02states we just need to add the4:04interactions which we can do on the4:06primary variant and the interactions4:08will be inherited by the other variants4:11I'll start by selecting the input field4:13then drag the interaction handle to the4:15focus variant now because this4:18interaction is triggered by an input4:20field we get some input specific options4:22here for when to trigger the interaction4:25in this case we're linking to our Focus4:27variant so naturally we'll trigger this4:29on Focus I'll leave the value set to any4:33which means we'll go to the focus4:34variant whether the user has typed into4:36the field or not let's repeat this for4:38the blur State select the input drag4:41over to our blur variant and we'll4:44choose to trigger on blur you might be4:46thinking what the heck does blur mean in4:49this context it means not4:53focused see so why do we need a4:56dedicated blur State when we already4:59have a state for when the input isn't5:01focused we have that first variant of5:03the input right yes but if the user has5:06typed something in the field we don't5:08want the label to move back down and5:10overlap with what the user has typed5:13thus we have our dedicated blur state5:15for when the input becomes defocused and5:18a value is set perfect let's actually5:22preview this from the primary variant5:24when I click there's our Focus variant5:26with the blue border and when I set a5:29value and click away there's our blur5:31variant that keeps the label up and out5:34of the way there's just one little issue5:36our blur variant is only triggered if5:38there's a value in the field if I delete5:41what I typed then click away nothing5:44happens easy fix let's get out of the5:47preview and select the input and Link it5:50to the primary variant this time we'll5:53say blur but only when the value is5:56empty that way it'll return to the5:58initial state if nothing is typed in the6:00field let's preview it again now6:03clicking goes to the focus variant and6:05clicking away from the empty field goes6:08right back and of course clicking typing6:11something and clicking away goes to our6:14special blur State just like it did6:15before let's exit the preview and link6:18up our last bit of logic validation to6:21do this right we have to consider two6:23sides of validation what happens when a6:25user tries to submit invalid data and6:28what happens when the user fixes it6:30first we'll create the interaction6:32linking to our invalid6:34variant and for this one we'll Choose6:36You Guessed It6:38invalid when we preview this I can type6:41some text that is not a valid email6:43address and framer logic gives me the6:45benefit of the doubt that I'm not done6:47typing yet but if I were to click submit6:49or click away the invalid value triggers6:52our invalid variant but now if I fix my6:55mistake we're still in the invalid State6:59let's get the preview and fix that by7:01selecting the input in the invalid7:03variant dragging an interaction over to7:06the focus variant and setting this to7:09trigger on valid all set now when we7:13preview and end up in that invalid7:16State fixing the error will revalidate7:19on the Fly and return us to the regular7:21State that's it now you know how and why7:25to turn an input into a component and7:27how to use variants to power custom7:29Focus blur invalid and valid states with7:33built-in validation logic that updates7:34in real time as a visitor types in a7:37field now head to framer and create some7:39super slick forms of your own

Watch on YouTube ↗

More in this topic

4 Ways to Update Form Status in Framer6:05
4 Ways to Update Form Status in Framer
Forms19K views · 1 year ago
Creating Custom Form Submit Buttons in Framer2:11
Creating Custom Form Submit Buttons in Framer
Forms18K views · 1 year ago
Using Optional Form Input Properties in Framer5:19
Using Optional Form Input Properties in Framer
Forms13K views · 1 year ago
Introducing: Framer Forms0:48
Introducing: Framer Forms
Announcement93K views · 1 year ago
Framer Update: Forms16:32
Framer Update: Forms
Framer Update36K views · 1 year ago
Creating your first form in Framer10:59
Creating your first form in Framer
Forms108K views · 1 year ago
The Input Component5:04
The Input Component
Forms18K views · 3 years ago

Create a free website with Framer, the website builder loved by startups, designers and agencies.