Skip to content
This repository has been archived by the owner on Jun 12, 2024. It is now read-only.

Commit

Permalink
fixed: validation exceptions, closes #219
Browse files Browse the repository at this point in the history
  • Loading branch information
MartijnR committed Jul 16, 2019
1 parent a9a211d commit e0acb10
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions public/js/src/module/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ Form.prototype.specialOcLoadValidate = function( includeRequired ) {
*/
Form.prototype.validateInput = function( control ) {
const that = this;
// There is a condition where a valuechange results in both an invalid-relevant and invalid-constraint,
// There is a condition where a value change results in both an invalid-relevant and invalid-constraint,
// where the invalid constraint is added *after* the invalid-relevant. I can reproduce in automated test (not manually).
// It is probably related due to the asynchronousity of contraint evaluation.
// It is probably related due to the asynchronicity of the constraint evaluation.
//
// To crudely resolve this, we remove any constraint error here.
// However we do want some of the other things that validateInput does (ie. updating the required "*" visibility), so
Expand All @@ -151,8 +151,11 @@ Form.prototype.validateInput = function( control ) {
// This is very unfortunate, but these are the kind of acrobatics that are necessary to "fight" the built-in behavior of Enketo's form engine.
return originalValidateInput.call( this, control )
.then( passed => {
if ( !passed && control.closest( '.question' ).classList.contains( 'invalid-relevant' ) ) {
that.setValid( control, 'constraint' );
if ( !passed ) {
const question = control.closest( '.question' );
if ( question && question.classList.contains( 'invalid-relevant' ) ) {
that.setValid( control, 'constraint' );
}
}
return passed;
} );
Expand Down

0 comments on commit e0acb10

Please sign in to comment.