Skip to content
This repository has been archived by the owner on Nov 29, 2023. It is now read-only.

Commit

Permalink
fixed: slow validation performance,
Browse files Browse the repository at this point in the history
  • Loading branch information
MartijnR committed Apr 1, 2015
1 parent 0c4bacf commit 00fee26
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/js/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -1985,16 +1985,25 @@ define( [ 'enketo-js/FormModel', 'enketo-js/widgets', 'jquery', 'enketo-js/plugi
* @return {boolean} whether the form contains any errors
*/
FormView.prototype.validateAll = function() {
var that = this,
$firstError;
var $firstError,
that = this;

//can't fire custom events on disabled elements therefore we set them all as valid
$form.find( 'fieldset:disabled input, fieldset:disabled select, fieldset:disabled textarea, ' +
'input:disabled, select:disabled, textarea:disabled' ).each( function() {
that.setValid( $( this ) );
} );
$form.find( 'input, select, textarea' ).not( '.ignore' ).trigger( 'validate' );

$form.find( '.question' ).each( function( q ) {
// only trigger validate on first input and huge **pure CSS** selector (huge performance impact)
$( this )
.find( 'input:not(.ignore):not(:disabled), select:not(.ignore):not(:disabled), textarea:not(.ignore):not(:disabled)' )
.eq( 0 )
.trigger( 'validate' );
} );

$firstError = $form.find( '.invalid-required, .invalid-constraint' ).eq( 0 );

if ( $firstError.length > 0 && window.scrollTo ) {
if ( this.pages.active ) {
// move to the first page with an error
Expand Down

0 comments on commit 00fee26

Please sign in to comment.