<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Yusuf Özünlü on Medium]]></title>
        <description><![CDATA[Stories by Yusuf Özünlü on Medium]]></description>
        <link>https://medium.com/@yusufznl?source=rss-6d3bdd64210f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*cdk5ACW5l15wZcwO736G1Q.jpeg</url>
            <title>Stories by Yusuf Özünlü on Medium</title>
            <link>https://medium.com/@yusufznl?source=rss-6d3bdd64210f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 22:22:37 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@yusufznl/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to validate forms in Nuxt with Vee-Validate]]></title>
            <link>https://medium.com/@yusufznl/how-to-validate-forms-in-nuxt-with-vee-validate-eef45508c3d4?source=rss-6d3bdd64210f------2</link>
            <guid isPermaLink="false">https://medium.com/p/eef45508c3d4</guid>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[vee-validate]]></category>
            <category><![CDATA[nuxtjs]]></category>
            <category><![CDATA[nuxt]]></category>
            <dc:creator><![CDATA[Yusuf Özünlü]]></dc:creator>
            <pubDate>Sun, 19 Jan 2020 21:15:33 GMT</pubDate>
            <atom:updated>2020-01-19T21:15:33.792Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*R_pOFb0hdYgXilDklvrWog.png" /></figure><p>Couple months ago me and my friend decided to build a forum. We initially wanted to do it on top of React with Redux and Node API, but halfway through routing problems with React and Redux not working with Turkish Windows pushed us to consider other options such as Nuxt and Vue. We started migration and one of the initial challenges that we had was form validations for fairly standard user registration operations. So with a bit of research and trial and error method, I managed to setup form validation system that I am happy to work with (Documentation was not clear and not covering Nuxt at least for my preference).</p><p>Without further ado I would like to write down steps that I took while setting it up, please feel free to comment and I appreciate the things that you can add to this setup.</p><p>First started with installing it via yarn</p><pre>yarn add vee-validate</pre><p>as of date of this article it was version 3.2.1</p><p>Next thing that you need to do is to create <em>vee-validate.js</em> under plugins directory and configuring <em>nuxt.config.js</em> accordingly</p><pre>plugins: [<br>  &quot;~/plugins/vee-validate.js&quot;<br>],<br>build: {<br>  transpile: [&quot;vee-validate/dist/rules&quot;],<em><br></em>}</pre><p>In the <em>vee-validate.js</em> you need to extend the built in rules that you want to use or you can register your custom made rules. For our registration form we are going to need the <em>required</em> rule.</p><pre><em>import </em>{ <em>extend </em>} <em>from </em>&quot;vee-validate&quot;;<br><em>import </em>{ required } <em>from </em>&quot;vee-validate/dist/rules&quot;;</pre><pre><em>extend</em>(&quot;required&quot;, {<br>  ...required,<br>  message: &quot;This field is required or your custom error message&quot;<br>});</pre><p>Lets try to use this rule in our form which has username password, password again and email fields. But first of all we need to import and register <em>ValidationObserver </em>and <em>ValidationProvider </em>components in our form component to make it work.</p><pre><em>import </em>{ ValidationObserver, ValidationProvider } <em>from </em>&quot;vee-validate&quot;;</pre><pre><em>export default </em>{<br>  components: {<br>    ValidationObserver: ValidationObserver,<br>    ValidationProvider: ValidationProvider<br>  },<br>.<br>.<br>.<br>}</pre><p><em>ValidationObserver </em>component will wrap our form to watch changes in our form and <em>ValidationProvider </em>will wrap our input fields to validate corresponding fields. Now our form looks like this.</p><pre>&lt;ValidationObserver <em>v-slot</em>=&quot;{ invalid }&quot;&gt;<br> &lt;b-form <em>@submit.prevent</em>=&quot;onSubmit&quot;&gt;<br>.<br>.<br>.<br> &lt;/b-form&gt;<br>&lt;/ValidationObserver&gt;</pre><p>and this is our username field</p><pre>&lt;ValidationProvider<br>          v-slot=&quot;{ errors }&quot;<br>          name=&quot;Username&quot;<br>          rules=&quot;required&quot;&gt;<br>          &lt;b-form-group id=&quot;input-group-4&quot; <br>                        label=&quot;Username:&quot; <br>                        label-for=&quot;input-4&quot;&gt;<br>            &lt;b-form-input<br>              id=&quot;input-4&quot;<br>              v-model=&quot;username&quot;<br>              required<br>              placeholder=&quot;Please enter a username&quot;<br>            /&gt;<br>            &lt;span class=&quot;input-invalid-message&quot;&gt;<br>              {{ errors[0] }}<br>            &lt;/span&gt;<br>          &lt;/b-form-group&gt;<br>&lt;/ValidationProvider&gt;</pre><p><em>ValidationProvider </em>will pick up the rule and will begin validating if the field is dirty. Second case we needed to cover was that the username should be unique so it has to make a call to our service some time after input field is typed and give feedback to user. Lets start with watching username value and making call to service</p><pre>data(){<br> return{<br>  isExist: false<br> }<br>},<br>username() {<br>  <em>const </em>that = <em>this;<br>  // We need to this so we can point to component in timeout</em></pre><pre><em>  clearTimeout</em>(<em>this</em>.timeout);<br>  // Clear old timeout on value change<br>   <em>this</em>.timeout = <em>setTimeout</em>(<em>function</em>() {<br>    that.$axios<br>      .post(&quot;/user/username/check&quot;, { username: that.username })<br>      .then(response =&gt; {<br>        that.isExist = response.data.isExist;<br>        <em>if </em>(that.isExist) {<br>          // do something if username exist<br>        } <em>else </em>{<br>          // do something if username not exist<br>        }<br>      });<br>  }, 1400);<em><br></em>}</pre><p>Now that we wrote our service it is time to extend our custom made username rule under <em>vee-validate.js</em>. We need to use validate method of vee-validate and we can write our custom check with it</p><pre><em>extend</em>(&quot;username&quot;,{<br>  validate(value, args) {<br>    console.log(args.val);<br>    <em>return </em>args.val === &#39;false&#39;;<br>  },<br>  params: [&#39;val&#39;],<br>  message: &quot;This username is already taken&quot;<br>});</pre><p>Lets add it to the username field</p><pre>&lt;ValidationProvider<br>          v-slot=&quot;{ errors }&quot;<br>          name=&quot;Username&quot;<br>          rules=&quot;`required|username:${isExist}`&quot;&gt;<br>          &lt;b-form-group id=&quot;input-group-4&quot; <br>                        label=&quot;Username:&quot; <br>                        label-for=&quot;input-4&quot;&gt;<br>            &lt;b-form-input<br>              id=&quot;input-4&quot;<br>              v-model=&quot;username&quot;<br>              required<br>              placeholder=&quot;Please enter a username&quot;<br>            /&gt;<br>            &lt;span class=&quot;input-invalid-message&quot;&gt;<br>              {{ errors[0] }}<br>            &lt;/span&gt;<br>          &lt;/b-form-group&gt;<br>&lt;/ValidationProvider&gt;</pre><p>We added our username rule to the provider and it makes validation every time <em>isExist </em>changes and we capture value on validate method params and thus we can check it.</p><p>This is just one example of what you can do with vee-validate on Nuxt which I was very satisfied with. It also has some very nice built in rules that covered most of our use cases. If you also get happy with vee-validate too don’t forget to star them on their <a href="https://github.com/logaretm/vee-validate">Github</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eef45508c3d4" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>