# AU2 validation in conditionally rendered component

**URL:** <https://discourse.aurelia.io/t/au2-validation-in-conditionally-rendered-component/5507>\
**Category:** vNext\
**Created:** [August 7, 2024, 10:42am UTC](https://discourse.aurelia.io/t/au2-validation-in-conditionally-rendered-component/5507 "2024-08-07T10:42:44Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![StefanNj](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/stefannj/32/1671_2.png) [@StefanNj](https://discourse.aurelia.io/u/StefanNj)\
**Post date:** [August 7, 2024, 10:42am UTC](https://discourse.aurelia.io/t/au2-validation-in-conditionally-rendered-component/5507/1 "2024-08-07T10:42:44Z")

</div>

I have an issue with validation controller reset on component detaching.

Have conditionally rendered component with @bindable model and validation rules on that model.

 ![image](https://canada1.discourse-cdn.com/flex027/uploads/aurelia/original/2X/b/b37011ccf2287c4eaa02bcb81d627ab13b4a1ca8.png)

Validation works perfectly after first component rendering, but when it gets detached and attached again validation results are not showing when validate() is called.  
I setup validation rules on attached after the model is bound, and validation rules and validation controller reset on detaching…

 ![image](https://canada1.discourse-cdn.com/flex027/uploads/aurelia/original/2X/4/4235dabf779a3ef3ee80be470d7cb74e1fe4b2ad.png)

---

<div class="post-metadata">

**Author:** ![Sayan751](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/sayan751/32/1861_2.png) [@Sayan751](https://discourse.aurelia.io/u/Sayan751)\
**Post date:** [August 10, 2024, 7:52am UTC](https://discourse.aurelia.io/t/au2-validation-in-conditionally-rendered-component/5507/2 "2024-08-10T07:52:45Z")

</div>

Hi @StefanNj! Thank you for reporting this issue. I can reproduce the issue and created a GH issue for this: [Validation in conditionally rendered component · Issue #2025 · aurelia/aurelia · GitHub](https://github.com/aurelia/aurelia/issues/2025). I intend to push a fix in coming days.

---

<div class="post-metadata">

**Author:** ![Sayan751](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/sayan751/32/1861_2.png) [@Sayan751](https://discourse.aurelia.io/u/Sayan751)\
**Post date:** [August 11, 2024, 2:42pm UTC](https://discourse.aurelia.io/t/au2-validation-in-conditionally-rendered-component/5507/3 "2024-08-11T14:42:52Z")

</div>

@StefanNj A [fix](https://github.com/aurelia/aurelia/pull/2027) has been merged. Try the next release 🙂

---

<div class="post-metadata">

**Author:** ![StefanNj](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/stefannj/32/1671_2.png) [@StefanNj](https://discourse.aurelia.io/u/StefanNj)\
**Post date:** [August 12, 2024, 7:54am UTC](https://discourse.aurelia.io/t/au2-validation-in-conditionally-rendered-component/5507/4 "2024-08-12T07:54:16Z")

</div>

@Sayan751 Thanks! Fix will be in beta.22?

---

<div class="post-metadata">

**Author:** ![Sayan751](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/sayan751/32/1861_2.png) [@Sayan751](https://discourse.aurelia.io/u/Sayan751)\
**Post date:** [August 12, 2024, 7:58am UTC](https://discourse.aurelia.io/t/au2-validation-in-conditionally-rendered-component/5507/5 "2024-08-12T07:58:20Z")

</div>

Yes, that is correct.

---

<div class="post-metadata">

**Author:** ![StefanNj](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/stefannj/32/1671_2.png) [@StefanNj](https://discourse.aurelia.io/u/StefanNj)\
**Post date:** [August 12, 2024, 10:15am UTC](https://discourse.aurelia.io/t/au2-validation-in-conditionally-rendered-component/5507/6 "2024-08-12T10:15:42Z")

</div>

@Sayan751 One more bug I noticed after the beta.18 update.

validation-container doesn’t remove the DefaultKeyPrefix.  
 ![image](https://canada1.discourse-cdn.com/flex027/uploads/aurelia/original/2X/0/07bcde2a37b6b13fbd66ea6c0cac64a7b23ad1c3.png)  
 ![image](https://canada1.discourse-cdn.com/flex027/uploads/aurelia/original/2X/c/c4c173f3f812e2afd13589bd7ac3f037eaced639.png)  
DefaultKeyPrefix=“validation”, and the prefix was not removed after displaying the validation message.

---

<div class="post-metadata">

**Author:** ![Sayan751](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/sayan751/32/1861_2.png) [@Sayan751](https://discourse.aurelia.io/u/Sayan751)\
**Post date:** [August 12, 2024, 11:51am UTC](https://discourse.aurelia.io/t/au2-validation-in-conditionally-rendered-component/5507/7 "2024-08-12T11:51:16Z")

</div>

It seems that you are using a different key. Is it possible that the property is `Location` and the i18n key, as seen in your screenshot, is `location`? If not, then please share a reproduction.

---

<div class="post-metadata">

**Author:** ![StefanNj](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/stefannj/32/1671_2.png) [@StefanNj](https://discourse.aurelia.io/u/StefanNj)\
**Post date:** [August 12, 2024, 2:08pm UTC](https://discourse.aurelia.io/t/au2-validation-in-conditionally-rendered-component/5507/8 "2024-08-12T14:08:08Z")

</div>

[Here](https://stackblitz.com/edit/au2-validation-issue-reproduction-discourse-5507-1dpfmq?file=src%2Findex.ts) is the reproduction. I can’t even override the default validation message.

 ![image](https://canada1.discourse-cdn.com/flex027/uploads/aurelia/original/2X/f/fd89dffbfad0d464fbd5224a214b6a2b069b3643.png)

---

<div class="post-metadata">

**Author:** ![Sayan751](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/sayan751/32/1861_2.png) [@Sayan751](https://discourse.aurelia.io/u/Sayan751)\
**Post date:** [August 12, 2024, 3:14pm UTC](https://discourse.aurelia.io/t/au2-validation-in-conditionally-rendered-component/5507/9 "2024-08-12T15:14:25Z")

</div>

Thanks for the reproduction @StefanNj. It seems like a regression from the recent work done for the new state rule. I will take care of it soon.

---

<div class="post-metadata">

**Author:** ![Sayan751](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/sayan751/32/1861_2.png) [@Sayan751](https://discourse.aurelia.io/u/Sayan751)\
**Post date:** [August 13, 2024, 1:00pm UTC](https://discourse.aurelia.io/t/au2-validation-in-conditionally-rendered-component/5507/10 "2024-08-13T13:00:25Z")

</div>

@StefanNj The [fix](https://github.com/aurelia/aurelia/pull/2029) is now merged.

---

<div class="post-metadata">

**Author:** ![StefanNj](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/stefannj/32/1671_2.png) [@StefanNj](https://discourse.aurelia.io/u/StefanNj)\
**Post date:** [August 14, 2024, 9:20am UTC](https://discourse.aurelia.io/t/au2-validation-in-conditionally-rendered-component/5507/11 "2024-08-14T09:20:55Z")

</div>

Thanks! I will try in the next release.
