Commit 641c1a6f by Vedran Karacic Committed by Vedran Karačić

Make state field required for CA and US.

parent c9f1d6d0
......@@ -89,6 +89,10 @@ define([
'select[name=country]'
];
if (['US', 'CA'].indexOf($('select[name=country]').val()) > -1) {
requiredFields.push('select[name=state]');
}
_.each(requiredFields, function(field) {
if ($(field).val() === '') {
event.preventDefault();
......@@ -261,11 +265,15 @@ define([
'<select name="state" class="select form-control" id="id_state"' +
'aria-required="true" required></select>'
);
$('#id_state').append($('<option>', {value: '', text: '<Choose state/province>'}));
$('#div_id_state').find('label').text('State/Province (required)');
_.each(states[country], function(value, key) {
$('#id_state').append($('<option>', {value: value, text: key}));
});
} else {
$(inputDiv).empty();
$('#div_id_state').find('label').text('State/Province');
// In order to change the maxlength attribute, the same needs to be changed in the Django form.
$(inputDiv).append(
'<input class="textinput textInput form-control" id="id_state"' +
......
......@@ -122,8 +122,8 @@ define([
'<option value="CA">Canada</option>' +
'<option value="HR">Croatia</option>' +
'</select></div><p class="help-block"></p></div>' +
'<div class="form-item"><div id="div_id_state"><div class="controls">' +
'<input name="state"></div></div>' +
'<div class="form-item"><div id="div_id_state"><label>State/Province</label>' +
'<div class="controls"><input name="state"></div></div></div>' +
'</fieldset>'
).appendTo('body');
BasketPage.onReady();
......@@ -136,6 +136,7 @@ define([
$('select[name=country]').val('CA').trigger('change');
expect($('#id_state').prop('tagName')).toEqual('SELECT');
expect($('#div_id_state').find('label').text()).toEqual('State/Province (required)');
});
it('should disable payment button before making ajax call', function () {
......@@ -242,6 +243,9 @@ define([
'<option value=""><Choose country></option>' +
'<option value="US">United States</option>' +
'</select></div><p class="help-block"></p></div>' +
'<div class="form-item"><div><select name="state">' +
'<option value=""><Choose state></option>' +
'</select></div><p class="help-block"></p></div>' +
'</fieldset>' +
'<div><input name="card_number">' +
'<p class="help-block"></p></div>' +
......@@ -274,61 +278,37 @@ define([
});
describe('cardHolderInformationValidation', function() {
it('should validate first name', function() {
$('input[name=first_name]').val('');
$('#payment-button').click();
expect(
$('input[name=first_name]').parentsUntil(
'form-item'
).find('~.help-block span').text()
).toEqual('This field is required');
it('should validate required fields', function() {
var requiredFields = [
'input[name=first_name]',
'input[name=last_name]',
'input[name=address_line1]',
'input[name=city]',
'select[name=country]'
];
_.each(requiredFields, function(field) {
$(field).val('');
$('#payment-button').click();
expect(
$(field).parentsUntil(
'form-item'
).find('~.help-block span').text()
).toEqual('This field is required');
});
});
it('should validate last name', function() {
$('input[name=last_name]').val('');
it('should validate state field', function() {
$('select[name=country]').val('US').trigger('change');
$('select[name=state]').val('');
$('#payment-button').click();
expect(
$('input[name=last_name]').parentsUntil(
$('select[name=state]').parentsUntil(
'form-item'
).find('~.help-block span').text()
).toEqual('This field is required');
});
it('should validate address', function() {
$('input[name=address_line1]').val('');
$('#payment-button').click();
expect(
$('input[name=address_line1]').parentsUntil(
'form-item'
).find('~.help-block span').text()
).toEqual('This field is required');
});
it('should validate city', function() {
$('input[name=city]').val('');
$('#payment-button').click();
expect(
$('input[name=city]').parentsUntil(
'form-item'
).find('~.help-block span').text()
).toEqual('This field is required');
});
it('should validate country', function() {
$('select[name=country]').val('');
$('#payment-button').click();
expect(
$('select[name=country]').parentsUntil(
'form-item'
).find('~.help-block span').text()
).toEqual('This field is required');
});
});
describe('cardInfoValidation', function() {
......
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