Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return;
}
this.setState({
alerts: [],
isSubmitting: true
});
var sub = this.state.submission;
sub.data = clone(this.data);
var request;
var method;
// Do the submit here.
if (this.state.form.action) {
method = this.state.submission._id ? 'put' : 'post';
request = Formiojs.request(this.state.form.action, method, sub);
}
else if (this.formio) {
request = this.formio.saveSubmission(sub);
}
if (request) {
request.then(function (submission) {
if (typeof this.props.onFormSubmit === 'function') {
this.props.onFormSubmit(submission);
}
this.setState({
isSubmitting: false,
alerts: [{
type: 'success',
message: 'Submission was ' + ((method === 'put') ? 'updated' : 'created')
}]
});
}
// Add the other filter.
if (this.props.component.filter) {
var filter = interpolate(this.props.component.filter, {data});
newUrl += ((newUrl.indexOf('?') === -1) ? '?' : '&') + filter;
}
// If they wish to return only some fields.
if (this.props.component.selectFields) {
this.options.params.select = this.props.component.selectFields;
}
// If this is a search, then add that to the filter.
newUrl += ((newUrl.indexOf('?') === -1) ? '?' : '&') + serialize(this.options.params);
formiojs.request(newUrl).then(data => {
// If the selectValue prop is defined, use it.
if (this.props.component.selectValues) {
this.setResult(get(data, this.props.component.selectValues, []), append);
}
// Attempt to default to the formio settings for a resource.
else if (data.hasOwnProperty('data')) {
this.setResult(data.data, append);
}
else if (data.hasOwnProperty('items')) {
this.setResult(data.items, append);
}
// Use the data itself.
else {
this.setResult(data, append);
}
});
this.component.settings.data.values = selectItems.slice(0);
break;
case 'resource':
var baseUrl = Formio.getAppUrl() + '/' + this.component.settings.data.resource;
var value_1 = this.component.settings.valueProperty.split('.')[1];
(new formio_service_1.FormioService(baseUrl)).loadSubmissions().subscribe(function (submission) {
for (var i = 0; i < submission.length; i++) {
selectItems.push({ id: submission[i].data[value_1], text: submission[i].data[value_1] });
}
_this.component.settings.data.values = selectItems.slice(0);
});
break;
case 'url':
var url = this.component.settings.data.url;
var this1_1 = this;
Formio.request(url).then(function (response) {
response.forEach(function (item) {
selectItems.push({ id: item[valueProperty], text: item[template] });
});
this1_1.component.settings.data.values = selectItems.slice(0);
});
break;
}
};
return SelectElement;
this.component.settings.data.values = selectItems.slice(0);
break;
case 'resource':
let baseUrl = Formio.getAppUrl() + '/' + this.component.settings.data.resource;
let value: string = this.component.settings.valueProperty.split('.')[1];
(new FormioService(baseUrl)).loadSubmissions().subscribe((submission: Array) => {
for(let i=0; i < submission.length; i++) {
selectItems.push({id: submission[i].data[value], text: submission[i].data[value]});
}
this.component.settings.data.values = selectItems.slice(0);
});
break;
case 'url':
let url: string = this.component.settings.data.url;
let this1 = this;
Formio.request(url).then(function(response: any) {
response.forEach((item: any) => {
selectItems.push({id: item[valueProperty], text: item[template]});
});
this1.component.settings.data.values = selectItems.slice(0);
});
break;
}
}
}
AddressElement.prototype.searchData = function (value) {
var this1 = this;
var selectItems = [];
var url = "//maps.googleapis.com/maps/api/geocode/json?address=" + value + "&sensor=false";
Formio.request(url, 'POST', {}, {}).then(function (response) {
response.results.forEach(function (item) {
selectItems.push({ id: item, text: item.formatted_address });
});
this1.selectedItem = selectItems.slice(0);
});
};
return AddressElement;
public searchData(value: any): void {
let this1 = this;
let selectItems: IdTextPair[] = [];
let url: string = "//maps.googleapis.com/maps/api/geocode/json?address="+value+"&sensor=false";
Formio.request(url, 'POST', {}, {}).then(function(response: any) {
response.results.forEach((item: any) => {
selectItems.push({id: item, text: item.formatted_address});
});
this1.selectedItem = selectItems.slice(0);
});
}
}