Join egghead, unlock knowledge.

Want more egghead?

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock This Lesson
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.


    Disallow Submitting an Empty Form with React Final Form 'pristine' property

    Tomasz ŁakomyTomasz Łakomy

    In this lesson we are going to see how you can use pristine property from React Final Form render prop to ensure that users won't be able to submit (or reset) an empty form.



    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson


    Instructor: 00:00 We have a form created with React Final Form. We have two fields, one for first name, the other one for second name. There are also two buttons, one for submit and the other for resetting the form.

    00:13 Right now, we are able to submit the form even though both first name and second name are empty, which doesn't make sense. We would like to be able only to submit the form whenever the user has entered their name or second name.

    00:28 In order to do that, there's actually pristine property from React Final Form. The pristine property is a Boolean value which is true whenever the form is completely empty. It's false when at least something has been written, if the form has been touched in any way.

    00:48 We can use it to disable the submit button whenever pristine is set to true, so whenever there is nothing inside of the form. Right now, the submit button is disabled. We can do exactly the same for the reset button.

    01:06 This is a desired effect. Right now, I cannot submit or reset the form. If I put in my name and my second name, I can submit the form, and I can also reset it.