forked from DGNum/gestioCOF
Commit gore : premier push vers git.eleves
This commit is contained in:
parent
e2e3bcd2b8
commit
392be324f6
2961 changed files with 295287 additions and 20 deletions
34
static/admin/js/prepopulate.js
Normal file
34
static/admin/js/prepopulate.js
Normal file
|
@ -0,0 +1,34 @@
|
|||
(function($) {
|
||||
$.fn.prepopulate = function(dependencies, maxLength) {
|
||||
/*
|
||||
Depends on urlify.js
|
||||
Populates a selected field with the values of the dependent fields,
|
||||
URLifies and shortens the string.
|
||||
dependencies - array of dependent fields id's
|
||||
maxLength - maximum length of the URLify'd string
|
||||
*/
|
||||
return this.each(function() {
|
||||
var field = $(this);
|
||||
|
||||
field.data('_changed', false);
|
||||
field.change(function() {
|
||||
field.data('_changed', true);
|
||||
});
|
||||
|
||||
var populate = function () {
|
||||
// Bail if the fields value has changed
|
||||
if (field.data('_changed') == true) return;
|
||||
|
||||
var values = [];
|
||||
$.each(dependencies, function(i, field) {
|
||||
if ($(field).val().length > 0) {
|
||||
values.push($(field).val());
|
||||
}
|
||||
})
|
||||
field.val(URLify(values.join(' '), maxLength));
|
||||
};
|
||||
|
||||
$(dependencies.join(',')).keyup(populate).change(populate).focus(populate);
|
||||
});
|
||||
};
|
||||
})(grp.jQuery);
|
Loading…
Add table
Add a link
Reference in a new issue