I've been struggling for hours to figure out how to delete or set to undefined parts of the code below:
$(document).ready(function() {
// Generate a simple captcha
function randomNumber(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min);
};
$('#captchaOperation').html([randomNumber(1, 100), '+', randomNumber(1, 200), '='].join(' '));
$('#defaultForm').bootstrapValidator({
message: 'This value is not valid',
fields: {
field1: {
message: 'The field is not valid',
validators: {
notEmpty: {
message: 'The field is required and can\'t be empty'
},
stringLength: {
min: 1,
max: 30,
message: 'The field must be more than 1 and less than 30 characters long'
},
regexp: {
regexp: /^[a-zA-Z0-9_\.]+$/,
message: 'The field can only consist of alphabetical, number, dot and underscore'
}
}
},
field2: {
message: 'The field is not valid',
validators: {
notEmpty: {
message: 'The field is required and can\'t be empty'
},
stringLength: {
min: 1,
max: 30,
message: 'The field must be more than 1 and less than 30 characters long'
},
regexp: {
regexp: /^[a-zA-Z0-9_\.]+$/,
message: 'The field can only consist of alphabetical, number, dot and underscore'
}
}
},
captcha: {
validators: {
callback: {
message: 'Wrong answer',
callback: function(value, validator) {
var items = $('#captchaOperation').html().split(' '), sum = parseInt(items[0]) + parseInt(items[2]);
return value == sum;
}
}
}
}
}
});
});
I'm looking to remove field1 from the above script. To do this, I can use the following code:
delete fields.field1; or
fields.field1 = undefined;
However, I'm having trouble understanding how to implement these lines of code.