Skip to content

Instantly share code, notes, and snippets.

@b4oshany
Last active August 29, 2015 14:13
Show Gist options
  • Save b4oshany/1d5e1c8c44d2486eaf80 to your computer and use it in GitHub Desktop.
Save b4oshany/1d5e1c8c44d2486eaf80 to your computer and use it in GitHub Desktop.
BootstrapValidator Library of Objects.....
Lets Call the js below bv.libs.js file.
```Javascript
var bv = {
message: {
notEmpty: 'This field is required and can\'t be empty.'
},
validators:{
enable_only: {
enabled: {
valid: true
}
},
options: {
enabled: {
valid: true
},
date: {
format: 'DD/MM/YYYY',
message: 'The value is not a valid date. The format of the date is DD/MM/YYYY'
}
}
},
fields: {
trn: {
validators: {
regexp: {
regexp: /\d{9}/,
message: 'This is not a trn number, \n trn must be nine (9) digits'
}
}
},
address:{
location: {
helpMessage: 'Give the name of the Building/Complex/Apt./Suite/lot # and housing development.',
validators: {
enabled: {
valid: true
}
}
},
street_num: {
validators: {
enabled: {
valid: true
}
}
},
street_name: {
validators: {
notEmpty: {
message: 'The street name is required and can\'t be empty.'
},
}
},
town_district: {
validators: {
notEmpty: {
message: 'The town/district is required and can\'t be empty.'
},
}
},
post_box: {
validators: {
digits: {
message: 'PO box can contain digits only.'
}
}
},
post_office: {
validators: {
enabled: {
valid: true
}
}
}
}
}
};
```
In another js file called, enter_address.js, we have the following:
```Javascript
$("#affiliated_address form[name='address_info']").bootstrapValidator({
field: bv.fields.address
}).on('success.form.bv', function (e) {
// Prevent form submission.
e.preventDefault();
// Get the form instance.
var form = e.target;
var $form = $(e.target);
$.post("address/update", $form.serialize(),
function (response) {
alert("OK");
});
});
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment