json-schema-form / angular-schema-form

Generate forms from a JSON schema, with AngularJS!
https://json-schema-form.github.io/angular-schema-form
MIT License
2.47k stars 653 forks source link

schemaFormValidate miss last field error on first digest cycle #907

Open ludovicPelle opened 7 years ago

ludovicPelle commented 7 years ago

Enhancement

As a developer, when I trigger schemaFormValidate, the last form field does not render errors, if i run another digest cycle , its ok

Expected behaviour

I expected schemaFormValidate works as expected

Actual behaviour

It actually need another digest cycle.

Gist/Plunker/Demo

I cant reproduce in plunker but, i reproduce on your demo page http://schemaform.io/examples/bootstrap-example.html open console $('[name="ngform"]').scope().$broadcast('schemaFormValidate') //the last field does not render error //Force a digest cycle $('[name="ngform"]').scope().$digest() //and the last field error appear

Related issues

@json-schema-form/angular-schema-form-lead

Anthropic commented 7 years ago

@ludovicPelle which example are you looking at? Actually which browser and version are you using?

ludovicPelle commented 7 years ago

On the "simple" example, tested with chrome 56 and firefox 49.

Anthropic commented 7 years ago

@ludovicPelle are I see what you mean now, thank you for your time :)

ludovicPelle commented 7 years ago

on v0.8.13 Ok after digging: it seems : validateField call (src/directives/schema-validate.js lign 163) miss digest cycle so if you have one field -> no validation, if you have more -> miss last field "digest"

Solution : wrap validateField call in scope.$applyAsync( function() {/***/}) (src/directives/schema-validate.js lign 163) seems to fix it

PS: i ll try to pull request but cannot launch npm test (have to update karma and socket.io due to angular-schema-form/node_modules/socket.io/lib/store.js:35 Store.prototype.proto = EventEmitter.prototype;

then after update on karma 1.7 -> 4 tests on master failed

PhantomJS 2.1.1 (Linux 0.0.0) directive should not add "has-success" class to radios field if a correct value is entered, but disableSuccessState is set on form FAILED expected false to be true assert@/home/loodub/Projects/angular-schema-form/node_modules/chai/chai.js:873:67 /home/loodub/Projects/angular-schema-form/node_modules/chai/chai.js:1172:16 get@/home/loodub/Projects/angular-schema-form/node_modules/chai/chai.js:3549:48 /home/loodub/Projects/angular-schema-form/test/directives/schema-form-test.js:2067:79 invoke@/home/loodub/Projects/angular-schema-form/test/lib/angular.js:4068:22 workFn@/home/loodub/Projects/angular-schema-form/test/lib/angular-mocks.js:2196:26 inject@/home/loodub/Projects/angular-schema-form/test/lib/angular-mocks.js:2168:41 /home/loodub/Projects/angular-schema-form/test/directives/schema-form-test.js:2049:11 undefined PhantomJS 2.1.1 (Linux 0.0.0) directive should not add "has-error" class to radios field if invalid value is entered, but disableErrorState is set on form FAILED expected false to be true assert@/home/loodub/Projects/angular-schema-form/node_modules/chai/chai.js:873:67 /home/loodub/Projects/angular-schema-form/node_modules/chai/chai.js:1172:16 get@/home/loodub/Projects/angular-schema-form/node_modules/chai/chai.js:3549:48 /home/loodub/Projects/angular-schema-form/test/directives/schema-form-test.js:2117:77 invoke@/home/loodub/Projects/angular-schema-form/test/lib/angular.js:4068:22 workFn@/home/loodub/Projects/angular-schema-form/test/lib/angular-mocks.js:2196:26 inject@/home/loodub/Projects/angular-schema-form/test/lib/angular-mocks.js:2168:41 /home/loodub/Projects/angular-schema-form/test/directives/schema-form-test.js:2097:11 undefined PhantomJS 2.1.1 (Linux 0.0.0) directive should not add "has-success" class to radios-inline field if a correct value is entered, but disableSuccessState is set on form FAILED expected false to be true assert@/home/loodub/Projects/angular-schema-form/node_modules/chai/chai.js:873:67 /home/loodub/Projects/angular-schema-form/node_modules/chai/chai.js:1172:16 get@/home/loodub/Projects/angular-schema-form/node_modules/chai/chai.js:3549:48 /home/loodub/Projects/angular-schema-form/test/directives/schema-form-test.js:2165:79 invoke@/home/loodub/Projects/angular-schema-form/test/lib/angular.js:4068:22 workFn@/home/loodub/Projects/angular-schema-form/test/lib/angular-mocks.js:2196:26 inject@/home/loodub/Projects/angular-schema-form/test/lib/angular-mocks.js:2168:41 /home/loodub/Projects/angular-schema-form/test/directives/schema-form-test.js:2147:11 undefined PhantomJS 2.1.1 (Linux 0.0.0) directive should not add "has-error" class to radios-inline field if invalid value is entered, but disableErrorState is set on form FAILED expected false to be true assert@/home/loodub/Projects/angular-schema-form/node_modules/chai/chai.js:873:67 /home/loodub/Projects/angular-schema-form/node_modules/chai/chai.js:1172:16 get@/home/loodub/Projects/angular-schema-form/node_modules/chai/chai.js:3549:48 /home/loodub/Projects/angular-schema-form/test/directives/schema-form-test.js:2215:77 invoke@/home/loodub/Projects/angular-schema-form/test/lib/angular.js:4068:22 workFn@/home/loodub/Projects/angular-schema-form/test/lib/angular-mocks.js:2196:26 inject@/home/loodub/Projects/angular-schema-form/test/lib/angular-mocks.js:2168:41 /home/loodub/Projects/angular-schema-form/test/directives/schema-form-test.js:2195:11 undefined LOG:

foobar
PhantomJS 2.1.1 (Linux 0.0.0): Executed 78 of 78 (4 FAILED) (0.824 secs / 0.681 secs)