<?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 leactz on Medium]]></title>
        <description><![CDATA[Stories by leactz on Medium]]></description>
        <link>https://medium.com/@leactz.za?source=rss-1bf0aaaf73a9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*l0QSjgG-OKt2_e7AblGZOw.png</url>
            <title>Stories by leactz on Medium</title>
            <link>https://medium.com/@leactz.za?source=rss-1bf0aaaf73a9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 06:00:24 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@leactz.za/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[Quasar 2: Q-input @clear event does not fire when using v-model.trim: Workaround]]></title>
            <link>https://medium.com/@leactz.za/quasar-2-q-input-clear-event-does-not-fire-when-using-v-model-trim-workaround-e3e7304807df?source=rss-1bf0aaaf73a9------2</link>
            <guid isPermaLink="false">https://medium.com/p/e3e7304807df</guid>
            <category><![CDATA[quasarframework]]></category>
            <category><![CDATA[frontend-development]]></category>
            <category><![CDATA[quasar]]></category>
            <category><![CDATA[vue-3]]></category>
            <category><![CDATA[quasar2]]></category>
            <dc:creator><![CDATA[leactz]]></dc:creator>
            <pubDate>Wed, 23 Feb 2022 12:32:00 GMT</pubDate>
            <atom:updated>2022-02-25T17:43:29.691Z</atom:updated>
            <cc:license>http://creativecommons.org/licenses/by/4.0/</cc:license>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*06gBRPahBE7VZKIPbYqQvw.png" /><figcaption>Visit <a href="http://quasar.dev/">quasar.dev</a> to learn more about Quasar Framework for Vue!</figcaption></figure><ul><li><a href="#8b68">Background and Context</a></li><li><a href="#c362">Github issue</a></li><li><a href="#4654">Jump to Solution</a></li></ul><p>I was taken aback yesterday during a call with my colleague, who is the backend developer for the frontend I am building with Quasar 2. I was showing off my latest changes, including API-driven filtering and sorting on a table containing specific user data. I was demoing the filtering, sorting and clearing actions when I suddenly realized that my inputs were not clearing like they had been before. Let’s unpack and see how we can fix it.</p><h4>Encountering the problem</h4><p>This particular table has a custom top row that contains a search input for each of the columns where the user can type a relevant term to fetch filtered results. Pretty straight forward, right? We also want the user to be able to quickly clear their search term in order to reload an unfiltered version of the data. Quasar makes this easy for us by providing a clearable Boolean attribute that can be applied to the relevant q-input. This will create a “clear” button, which will fire the @clear event. (Bear in mind here that the @ here is shorthand for v-on , the Vue directive that listens for events.</p><p>In this @clear event you can then reset your model-valueto an empty string, retrieve the unfiltered data, or do whatever you like.</p><p>It will look like this: &lt;q-input v-model=&quot;modelprop&quot; clearable @clear=&quot;clearEvent()&quot;&gt;</p><p>During some of my initial tests (using <a href="https://medium.com/u/47c842e55929">Cypress.io</a>), I realized that I need to trim the whitespace from my inputs. The easiest way to do this is to add the .trim directive to v-model directly, as in so:</p><p>&lt;q-input v-model.trim=&quot;modelprop&quot; clearable @clear=&quot;clearEvent()&quot;&gt;</p><p>It was after adding this .trim directive to my v-model that my @clear event stopped firing. I am happy that I had created a separate feature branch in git for my testing setup. To find what had changed on my search inputs, I checked out my working UI branch and immediately saw that the only change in my input markup was the v-model.trim directive. This made it easy to give the problem a quick Google. I was not the first to encounter the problem.</p><h4>Github Issue</h4><p><a href="https://github.com/quasarframework/quasar/issues/10376">This thread describes the problem.</a> I must confess that I spot-read threads like this more often than not. My eye caught (very paraphrased) something to the effect of “Yes, v-model.trim does break the @clear event in Quasar 2, but this is more of a Vue problem than a Quasar problem, and not so easy to sort out. Here is a workaround.”</p><p>Here it is important to note that Quasar 2 uses Vue 3, so there will be some changes in behaviour if you are used to Quasar 1 or Vue 2. Please go and read the issue for yourself. I will not go further into it here, but instead explain the solution and show you how I implemented it.</p><h4>The solution</h4><p>We will be removing the clearable attribute and @clear event from our input and instead use slots to easily create an alternative clear button with a click event, instead of using the native @clear event provided us by the q-input .</p><p>Quasar provides us with handy prepend and append slots we can use within our inputs. My particular search inputs were already using the prepend slot to display a little search icon for the user, like so:</p><pre>&lt;q-input<br>  v-model.trim=&quot;modelprop&quot;<br>  clearable <br>  @clear=&quot;clearEvent()&quot;&gt;</pre><pre>  &lt;template v-slot:prepend&gt;<br>    &lt;q-icon name=&quot;search&quot; /&gt;<br>  &lt;/template&gt;</pre><pre>&lt;/q-input&gt;</pre><p>So it is as easy as 1, 2, 3 to add an append slot to sort out our clearable dilemma, like so: (note: v-slot: can also be written as # shorthand, like so: &lt;template #prepend&gt; instead of &lt;template v-slot:prepend&gt; .</p><pre>&lt;q-input<br>  v-model.trim=&quot;modelprop&quot;&gt;</pre><pre>  &lt;template v-slot:prepend&gt;<br>    &lt;q-icon name=&quot;search&quot; /&gt;<br>  &lt;/template&gt;</pre><pre>  &lt;template v-slot:append&gt;<br>    &lt;q-btn<br>      flat<br>      round size=&quot;xs&quot; <br>      icon=&quot;clear&quot; <br>      @click=&quot;clearEvent()&quot;/&gt;<br>  &lt;/template&gt;</pre><pre>&lt;/q-input&gt;</pre><p>Furthermore, you can add a conditional to the new button to behave even more like the native clearable attribute— by only displaying it if the user has entered something in the input, like so:</p><pre>&lt;q-input<br>  v-model.trim=&quot;modelprop&quot;&gt;</pre><pre>&lt;template v-slot:prepend&gt;<br>    &lt;q-icon name=&quot;search&quot; /&gt;<br>  &lt;/template&gt;</pre><pre>  &lt;template v-slot:append&gt;<br>    &lt;q-btn <br>      v-if=&quot;modelprop !== &#39;&#39;&quot;<br>      flat<br>      round<br>      size=&quot;xs&quot;<br>      icon=&quot;clear&quot;<br>      @click=&quot;clearEvent()&quot;/&gt;<br>  &lt;/template&gt;</pre><pre>&lt;/q-input&gt;</pre><p>And that is all there is to it!</p><p>I hope that this has been a helpful and relatively easy read to fix the clear event breaking on q-input using v-model.trim in Quasar 2!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e3e7304807df" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>