Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getRandomInt(min, max) {
- return Math.floor(Math.random() * (max - min + 1)) + min;
- }
- function getCheckDigit(value) {
- const nif = value.toString();
- const total = nif[0] * 9 + nif[1] * 8 + nif[2] * 7 + nif[3] * 6 + nif[4] * 5 + nif[5] * 4 + nif[6] * 3 + nif[7] * 2;
- const modulo11 = (Number(total) % 11);
- const checkDigit = modulo11 < 2 ? 0 : 11 - modulo11;
- return checkDigit;
- }
- function getNif(minAndMax) {
- var minAndMaxSplitted = minAndMax.split("|");
- var min= parseInt(minAndMaxSplitted[0]);
- var max= parseInt(minAndMaxSplitted[1]);
- var random = getRandomInt(min, max);
- var checkDigit = getCheckDigit(random);
- var nif = random.toString() + checkDigit.toString();
- return nif;
- }
- function makeDate(start, end) {
- var date = new Date(start.getTime() + Math.random() * (end.getTime() - start.getTime()));
- date = $.datepicker.formatDate("dd-mm-yy", date);
- return date;
- }
- function makeValue(type, length, minDate, maxDate) {
- var characters = "";
- if(type == 'only-letters')
- {
- characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
- } else if(type == 'only-numbers') {
- characters = "1234567890";
- }else if(type == 'money') {
- characters = "1234567890";
- }else if(type == 'no-numbers') {
- characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZÇ#$%&/()?.-*€";
- } else {
- characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZÇ#$%&/()?.-*€123456789";
- }
- var result = '';
- var charactersLength = characters.length;
- for ( var i = 0; i < length; i++ ) {
- result += characters.charAt(Math.floor(Math.random() * charactersLength));
- }
- if(type=='money')
- {
- result = (Number(result) / 100).toString();
- }
- return result;
- }
- function getRandomInt(min, max) {
- min = Math.ceil(min);
- max = Math.floor(max);
- return Math.floor(Math.random() * (max - min + 1)) + min;
- }
- $('input[class*="form-field-input"]:not(.form-field-input-button)').each(function(){
- var $this = $(this);
- if(!$this.is(":visible") || $this.is('[readonly]'))
- return;
- var value = "";
- if($this.hasClass("js-form-address-line"))
- return;
- if($this.hasClass("input-mask-postCode")){
- value = "1495-139";
- $this.val(value);
- $this.blur();
- return;
- } else if($this.hasClass("input-mask-iban")){
- value = "003600709910009773572";
- $this.val(value);
- $this.blur();
- return;
- } else if($this.hasClass("input-mask-money")){
- value = makeValue('money', 5);
- } else if($this.hasClass("input-mask-phone")){
- if($this.data("valRegexPattern").startsWith("^2"))
- {
- value = "21";
- }else if($this.hasClass("input-mask-phone")){
- value = "91";
- }
- value += makeValue('only-numbers', 7);
- } else
- if($this.hasClass("form-field-input-email"))
- {
- value = makeValue('only-letters', 7)+"@"+makeValue('only-letters', 4)+".pt";
- } else
- if($this.hasClass("input-mask-only-letters"))
- {
- value = makeValue('only-letters', 30);
- } else if($this.hasClass("input-mask-only-numbers"))
- {
- if($this.data("valIsvalidnif"))
- {
- value = getNif("10000000|29999999")
- } else {
- value = makeValue('only-numbers', 2);
- }
- } else if($this.hasClass('input-mask-no-numbers'))
- {
- value = makeValue('no-numbers', 30);
- } else if($this.hasClass('form-field-input-date'))
- {
- console.log($this.data("scFieldName"),$this.datepicker('getStartDate'), $this.datepicker('getEndDate'))
- value = makeDate($this.datepicker('getStartDate'), $this.datepicker('getEndDate'));
- } else {
- value = makeValue('', 10);
- }
- $this.val(value);
- $this.trigger("change");
- });
- $('.form-field-custom-dropdownlist:visible select[class*="form-field-select"]').each(function(){
- var $this = $(this);
- var options = $this.siblings(".select-items").children();
- var optionToChoose = getRandomInt(1, options.length-1);
- var option = $(options[optionToChoose]);
- option.data("select-item").interact.call(option[0]);
- })
- $('.form-field-label-radiobuttonlist:visible').each(function(){
- var $this = $(this);
- var options = $this.parent().find('input.form-field-input-radiobutton');
- var selectedOption = options.filter(function(){
- return $(this).is(":checked");
- });
- if(selectedOption.length == 0)
- $($this.parent().find('.form-field-inner-label-radiobuttonlist')[0]).click();
- })
- $('.form-field-label-checkbox.form-field-required:visible').each(function(){
- var $this = $(this);
- $this.find('.form-field-span-checkbox').click();
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement