angular-validation-schema icon indicating copy to clipboard operation
angular-validation-schema copied to clipboard

Its not working with ng-include and directive with template

Open sajithmx opened this issue 9 years ago • 20 comments

Its not working with ng-include and directive with template

sajithmx avatar Aug 21 '15 12:08 sajithmx

@sajithmx Would you check for this?

hueitan avatar Sep 16 '15 03:09 hueitan

what I have to check ?

sajithmx avatar Sep 16 '15 07:09 sajithmx

Wrong person sorry @sajithmx

hueitan avatar Sep 16 '15 08:09 hueitan

any updates on my issue ?

sajithmx avatar Sep 16 '15 11:09 sajithmx

Have you success on using only angular-validation?

hueitan avatar Sep 18 '15 02:09 hueitan

@sajithmx did you ever resolve this?

@huei90 I had angular-validation working fine, the schema stuff definitely doesn't work from within an include, any ideas

chorsnell avatar Oct 26 '16 15:10 chorsnell

Further investigation...

The querySelectorAll on line 125 isnt detecting the elements on the DOM as the include hasn't finished loading at that point.

Trying to find a fix

chorsnell avatar Oct 26 '16 16:10 chorsnell

ok so I've tried adding a delay, by either $includeContentLoaded or just a hacky simple setTimeout, and it then picks up the form elements from querySelectorAll, and even applies the correct parameters when I inspect element, but it doesn't actually work

I dont really know enough about the inner workings of angular-validation and why this would be the case, as it looks like the delay on adding the schema is causing its own problems, so @huei90 if you could give me some input that would help greatly :)

chorsnell avatar Oct 27 '16 11:10 chorsnell

I'm sorry that I didn't have time look into this. I'm calling @thetutlage . 😄

hueitan avatar Oct 27 '16 11:10 hueitan

@thetutlage @huei90 any ideas guys? if you aren't able to support let me know and I will make other arrangements, however this is ideal for my use case and would love to utilise it :)

chorsnell avatar Nov 01 '16 09:11 chorsnell

@poppahorse I would suggest you try fixing angular-validation-schema and make it works with angular-validation.

I believe you already know what schema is and it benefits our code 😄

hueitan avatar Nov 01 '16 10:11 hueitan

@huei90 I would love to fix it but a) I need it for something fairly time sensitive, and b) as mentioned above I'm not sure on the reasoning why delaying adding the parameters even to angular-validation would prevent the validation from happening.

I managed to get querySelectorAll to detect the fields within the include, however at that point, even though inspect shows the params in place correctly (via schema), the validation just doesn't trigger.

I am happy to try and fix it, but going to need pointing in the right direction as to why the validation doesn't occur after a delay. If I made a plnkr would you be able to have a look? :smiley:

chorsnell avatar Nov 01 '16 16:11 chorsnell

sure, you can paste the link and everyone can check it 🍻

hueitan avatar Nov 01 '16 17:11 hueitan

Right so here is a demo with the vanilla angular-validation-schema.js

https://plnkr.co/edit/NLRGdUlrLvX9hpEfJiRn?p=preview

If you look in the console, I have got it to output the detected input fields for both forms. The first form doesn't detect any (as the include hasn't loaded yet), while the second one detects them fine.

Next is a version with a modified angular-validation-schema.js that will delay the querySelectorAll. Its just a dirty setTimeout (line 124) at the moment, but behaviour is the same if I use $includeContentLoaded to detect completion of the include.

https://plnkr.co/edit/acHclPuZaTEdYLnHxQFf?p=preview

In the console, its detecting all the correct inputs opn both forms, but now neither forms work (with or without include), because I suspect the delay is breaking something.

@huei90 this is where I could do with your assistance, as unsure why or how the delay is breaking something, but it seems that is the only way to get it working nicely with includes. Any help you can offer would be greatly appreciated :+1:

chorsnell avatar Nov 02 '16 10:11 chorsnell

@huei90 I'm having the same issues and looking at @poppahorse plnkr examples it's a bit of a mystery why the delay would cause the validation to stop firing. Looks like will need your input to help us progress. Thanks in advance :)

jcjmcclean avatar Nov 02 '16 14:11 jcjmcclean

hmmm.. interesting, I'm not sure but it is possible because angular-validation uses $timeout too 😵

hueitan avatar Nov 04 '16 16:11 hueitan

@huei90 ok cool, so are you saying the delay for angular-validation needs lengthening to wait for the includes also?

Or that the delay for angular-validation-schema needs to be > the includes but < whatever the $timeout you mentioned above does? :stuck_out_tongue:

chorsnell avatar Nov 08 '16 11:11 chorsnell

@huei90 are we supposed to just set a $timeout so validation waits until the includes have loaded? Is there not a better way to detect that the includes have loaded before running validation? It feels super hacky just using $timeout.

jcjmcclean avatar Nov 11 '16 17:11 jcjmcclean

@huei90 @thetutlage any ideas? :)

chorsnell avatar Nov 22 '16 13:11 chorsnell

It feels super hacky just using $timeout.

I think so, we need a more solid solution on this.

@poppahorse I have no idea about it, and looks like @thetutlage is busy on something else.

hueitan avatar Nov 22 '16 15:11 hueitan