Commit 4203c1e5 by Will Daly

Use disabled property to prevent IE9 users from clicking disabled buttons

parent 35ec3611
...@@ -78,7 +78,10 @@ define([ ...@@ -78,7 +78,10 @@ define([
}; };
var expectPaymentButtonEnabled = function( isEnabled ) { var expectPaymentButtonEnabled = function( isEnabled ) {
var isDisabled = $( '#pay_button' ).hasClass('is-disabled'); var appearsDisabled = $( '#pay_button' ).hasClass( 'is-disabled' ),
isDisabled = $( '#pay_button' ).prop( 'disabled' );
expect( !appearsDisabled ).toEqual( isEnabled );
expect( !isDisabled ).toEqual( isEnabled ); expect( !isDisabled ).toEqual( isEnabled );
}; };
...@@ -92,6 +95,7 @@ define([ ...@@ -92,6 +95,7 @@ define([
// Activate button should be displayed and disabled // Activate button should be displayed and disabled
expect( activateButton.length ).toEqual(1); expect( activateButton.length ).toEqual(1);
expect( activateButton.hasClass( 'is-disabled' ) ).toBe( true ); expect( activateButton.hasClass( 'is-disabled' ) ).toBe( true );
expect( activateButton.prop( 'disabled' ) ).toBe( true );
}; };
var goToPayment = function( requests, kwargs ) { var goToPayment = function( requests, kwargs ) {
......
...@@ -54,7 +54,10 @@ define([ ...@@ -54,7 +54,10 @@ define([
}; };
var expectSubmitEnabled = function( isEnabled ) { var expectSubmitEnabled = function( isEnabled ) {
var isDisabled = $('#next_step_button').hasClass('is-disabled'); var appearsDisabled = $( '#next_step_button' ).hasClass( 'is-disabled' ),
isDisabled = $( '#next_step_button' ).prop( 'disabled' );
expect( !appearsDisabled ).toBe( isEnabled );
expect( !isDisabled ).toBe( isEnabled ); expect( !isDisabled ).toBe( isEnabled );
}; };
......
...@@ -73,7 +73,10 @@ define([ ...@@ -73,7 +73,10 @@ define([
}; };
var expectSubmitEnabled = function( isEnabled ) { var expectSubmitEnabled = function( isEnabled ) {
var isDisabled = $( '#submit_button' ).hasClass( 'is-disabled' ); var appearsDisabled = $( '#submit_button' ).hasClass( 'is-disabled' ),
isDisabled = $( '#submit_button' ).prop( 'disabled' );
expect( !appearsDisabled ).toEqual( isEnabled );
expect( !isDisabled ).toEqual( isEnabled ); expect( !isDisabled ).toEqual( isEnabled );
}; };
...@@ -82,7 +85,7 @@ define([ ...@@ -82,7 +85,7 @@ define([
setFixtures( setFixtures(
'<div id="current-step-container"></div>' + '<div id="current-step-container"></div>' +
'<input type="button" id="submit_button" class="is-disabled"></input>' '<input type="button" id="submit_button"></input>'
); );
TemplateHelpers.installTemplate( 'templates/verify_student/webcam_photo' ); TemplateHelpers.installTemplate( 'templates/verify_student/webcam_photo' );
}); });
......
...@@ -34,6 +34,14 @@ var edx = edx || {}; ...@@ -34,6 +34,14 @@ var edx = edx || {};
// Track a virtual pageview, for easy funnel reconstruction. // Track a virtual pageview, for easy funnel reconstruction.
window.analytics.page( 'payment', this.templateName ); window.analytics.page( 'payment', this.templateName );
// Set the payment button to disabled by default
this.setPaymentEnabled( false );
// The activate button is always disabled
$( '#activate_button' )
.addClass( 'is-disabled' )
.prop( 'disabled', true );
// Update the contribution amount with the amount the user // Update the contribution amount with the amount the user
// selected in a previous screen. // selected in a previous screen.
if ( templateContext.contributionAmount ) { if ( templateContext.contributionAmount ) {
...@@ -69,8 +77,9 @@ var edx = edx || {}; ...@@ -69,8 +77,9 @@ var edx = edx || {};
if ( _.isUndefined( isEnabled ) ) { if ( _.isUndefined( isEnabled ) ) {
isEnabled = true; isEnabled = true;
} }
$( '#pay_button' )
$( '#pay_button' ).toggleClass( 'is-disabled', !isEnabled ); .toggleClass( 'is-disabled', !isEnabled )
.prop( 'disabled', !isEnabled );
}, },
createOrder: function() { createOrder: function() {
...@@ -142,7 +151,7 @@ var edx = edx || {}; ...@@ -142,7 +151,7 @@ var edx = edx || {};
}); });
// Re-enable the button so the user can re-try // Re-enable the button so the user can re-try
$( '#pay_button' ).removeClass( 'is-disabled' ); this.setPaymentEnabled( true );
}, },
getPaymentAmount: function() { getPaymentAmount: function() {
......
...@@ -50,7 +50,7 @@ var edx = edx || {}; ...@@ -50,7 +50,7 @@ var edx = edx || {};
var fullName = $( '#new-name' ).val(); var fullName = $( '#new-name' ).val();
// Disable the submit button to prevent duplicate submissions // Disable the submit button to prevent duplicate submissions
$( '#next_step_button' ).addClass( 'is-disabled' ); this.setSubmitButtonEnabled( false );
// On success, move on to the next step // On success, move on to the next step
this.listenToOnce( this.model, 'sync', _.bind( this.nextStep, this ) ); this.listenToOnce( this.model, 'sync', _.bind( this.nextStep, this ) );
...@@ -69,7 +69,7 @@ var edx = edx || {}; ...@@ -69,7 +69,7 @@ var edx = edx || {};
var errorMsg = gettext( 'An unexpected error occurred. Please try again later.' ); var errorMsg = gettext( 'An unexpected error occurred. Please try again later.' );
// Re-enable the submit button to allow the user to retry // Re-enable the submit button to allow the user to retry
$( '#next_step_button' ).removeClass( 'is-disabled' ); this.setSubmitButtonEnabled( true );
if ( xhr.status === 400 ) { if ( xhr.status === 400 ) {
errorMsg = xhr.responseText; errorMsg = xhr.responseText;
...@@ -91,6 +91,12 @@ var edx = edx || {}; ...@@ -91,6 +91,12 @@ var edx = edx || {};
title = $( this ).parent(); title = $( this ).parent();
title.toggleClass( 'is-expanded' ); title.toggleClass( 'is-expanded' );
title.attr( 'aria-expanded', !title.attr( 'aria-expanded' ) ); title.attr( 'aria-expanded', !title.attr( 'aria-expanded' ) );
},
setSubmitButtonEnabled: function( isEnabled ) {
$( '#next_step_button' )
.toggleClass( 'is-disabled', !isEnabled )
.prop( 'disabled', !isEnabled );
} }
}); });
......
...@@ -231,6 +231,9 @@ ...@@ -231,6 +231,9 @@
render: function() { render: function() {
var renderedHtml; var renderedHtml;
// Set the submit button to disabled by default
this.setSubmitButtonEnabled( false );
// Load the template for the webcam into the DOM // Load the template for the webcam into the DOM
renderedHtml = _.template( $( this.template ).html(), {} ); renderedHtml = _.template( $( this.template ).html(), {} );
$( this.el ).html( renderedHtml ); $( this.el ).html( renderedHtml );
...@@ -258,7 +261,7 @@ ...@@ -258,7 +261,7 @@
reset: function() { reset: function() {
// Disable the submit button // Disable the submit button
$( this.submitButton ).addClass( "is-disabled" ); this.setSubmitButtonEnabled( false );
// Reset the video capture // Reset the video capture
this.backend.reset(); this.backend.reset();
...@@ -288,7 +291,7 @@ ...@@ -288,7 +291,7 @@
this.model.set( this.modelAttribute, this.backend.getImageData() ); this.model.set( this.modelAttribute, this.backend.getImageData() );
// Enable the submit button // Enable the submit button
$( this.submitButton ).removeClass( "is-disabled" ); this.setSubmitButtonEnabled( true );
} }
}, },
...@@ -305,6 +308,12 @@ ...@@ -305,6 +308,12 @@
shown: true shown: true
}); });
} }
},
setSubmitButtonEnabled: function( isEnabled ) {
$( this.submitButton )
.toggleClass( 'is-disabled', !isEnabled )
.prop( 'disabled', !isEnabled );
} }
}); });
......
...@@ -140,11 +140,11 @@ ...@@ -140,11 +140,11 @@
<a class="next action-primary is-disabled" id="pay_button"> <a class="next action-primary is-disabled" id="pay_button">
<%- gettext( "Go to payment" ) %> <%- gettext( "Go to payment" ) %>
</a> </a>
<% } else { %> <% } else { %>
<a class="next action-primary is-disabled" id="activate_button"> <a class="next action-primary is-disabled" id="activate_button">
<%- gettext( "Activate Your Account" ) %> <%- gettext( "Activate Your Account" ) %>
</a> </a>
<% } %> <% } %>
</nav> </nav>
<form id="payment-processor-form"></form> <form id="payment-processor-form"></form>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment