ECOM-626 Added required check for select dropdowns and validation
This commit is contained in:
@@ -52,10 +52,10 @@ describe('edx.utils.validate', function () {
|
||||
createFixture('text', 'username', true, MIN_LENGTH, MAX_LENGTH, '');
|
||||
expectInvalid(REQUIRED_ERROR_FRAGMENT);
|
||||
});
|
||||
|
||||
|
||||
it('fails if a field is provided a value below its minimum character limit', function () {
|
||||
createFixture('text', 'username', false, MIN_LENGTH, MAX_LENGTH, SHORT_STRING);
|
||||
|
||||
|
||||
// Verify optional field behavior
|
||||
expectInvalid(MIN_ERROR_FRAGMENT);
|
||||
|
||||
@@ -66,7 +66,7 @@ describe('edx.utils.validate', function () {
|
||||
|
||||
it('succeeds if a field with no minimum character limit is provided a value below its maximum character limit', function () {
|
||||
createFixture('text', 'username', false, null, MAX_LENGTH, SHORT_STRING);
|
||||
|
||||
|
||||
// Verify optional field behavior
|
||||
expectValid();
|
||||
|
||||
@@ -154,6 +154,31 @@ describe('edx.utils.validate', function () {
|
||||
expectInvalid(REQUIRED_ERROR_FRAGMENT);
|
||||
});
|
||||
|
||||
it('succeeds if a select is optional, or required and default is selected, but fails if a required select has the default option selected', function () {
|
||||
var select = [
|
||||
'<select id="dropdown" name="country">',
|
||||
'<option value="" data-isdefault="true">Please select a country</option>',
|
||||
'<option value="BE">Belgium</option>',
|
||||
'<option value="DE">Germany</option>',
|
||||
'</select>'
|
||||
].join('');
|
||||
|
||||
setFixtures(select);
|
||||
|
||||
dropdown = $('#dropdown');
|
||||
|
||||
// Optional
|
||||
expectValid();
|
||||
|
||||
// Required, default text selected
|
||||
dropdown.attr('required', true);
|
||||
expectInvalid(REQUIRED_ERROR_FRAGMENT);
|
||||
|
||||
// Required, country selected
|
||||
dropdown.val('BE');
|
||||
expectValid();
|
||||
});
|
||||
|
||||
it('returns a custom error message if an invalid field has one attached', function () {
|
||||
// Create a blank required field
|
||||
createFixture('text', 'username', true, MIN_LENGTH, MAX_LENGTH, '');
|
||||
|
||||
@@ -87,7 +87,18 @@ var edx = edx || {};
|
||||
},
|
||||
|
||||
isBlank: function( $el ) {
|
||||
return ( $el.attr('type') === 'checkbox' ) ? !$el.prop('checked') : !$el.val();
|
||||
var type = $el.attr('type'),
|
||||
isBlank;
|
||||
|
||||
if ( type === 'checkbox' ) {
|
||||
isBlank = !$el.prop('checked');
|
||||
} else if ( type === 'select' ) {
|
||||
isBlank = ( $el.data('isdefault') === true );
|
||||
} else {
|
||||
isBlank = !$el.val();
|
||||
}
|
||||
|
||||
return isBlank;
|
||||
},
|
||||
|
||||
email: {
|
||||
|
||||
Reference in New Issue
Block a user