Skip to content

Commit

Permalink
ajaxForm now autofills from url params
Browse files Browse the repository at this point in the history
  • Loading branch information
jrdbnntt committed Jan 29, 2017
1 parent 4b9ae57 commit 668fafa
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion webapp/js/plugins/ajaxForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,25 @@
parsleyOptions: {}
};

function fillValuesFromUrlParams(form) {
var sPageURL = decodeURIComponent(window.location.search.substring(1)),
sURLVariables = sPageURL.split('&'),
param, name, value, field, i;

for (i = 0; i < sURLVariables.length; i++) {
param = sURLVariables[i].split('=');

if (param.length === 2) {
name = param[0].replace('"','');
value = param[1];
field = form.find('[name="' + name + '"]');
if (field.length === 1 && field.is('input, select, textarea')) {
field.val(value);
}
}
}
}

function ajaxJsonSubmit(options) {
var dfd = $.Deferred();
var defaultAjaxOptions = {
Expand Down Expand Up @@ -72,11 +91,12 @@
if (!o.setDisabled) {
o.setDisabled = function() {
self.find('input, textarea, select, button').prop('disabled', value);
}
};
}

var parsleyFormInstance = this.parsley(o.parsleyOptions);
var canSubmit = true;
fillValuesFromUrlParams($(this));

this.on('submit', function(ev) {
ev.preventDefault();
Expand Down

0 comments on commit 668fafa

Please sign in to comment.