|
@@ -162,9 +162,20 @@
|
|
|
let input = $(this).closest('.position-relative').prev('[stag-suggest]');
|
|
|
input.val(label);
|
|
|
input.data('suggest-data', data);
|
|
|
+
|
|
|
+ let scope = input.attr('stag-suggest-scope');
|
|
|
+ if(!scope) scope = 'form';
|
|
|
+ scope = $(scope);
|
|
|
+
|
|
|
for(let x in data) {
|
|
|
if(data.hasOwnProperty(x)) {
|
|
|
input.attr('data-' + x, data[x]);
|
|
|
+
|
|
|
+ // auto-populate if there's a field matching data-name="x" in the scope
|
|
|
+ if(scope.find('[data-name="' + x + '"]').length) {
|
|
|
+ scope.find('[data-name="' + x + '"]').val(data[x]).trigger('change');
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
input.trigger('input');
|