Hey All,
im new in the survey123 js api, and at the moment im trying to get the coordinates x and y from the map component.
im using onFormLoaded to get the Form. And with onQuestionValueChanged i wanted to get the x and y values, whenever i click on the map. But my problem is, the values in the questtion map are always null
let webform = new Survey123WebForm({
itemId: '...',
container: 'test',
clientId: '...',
portalUrl: '...',
onFormLoaded:(data) =>
{
console.log(data);
console.log(data.form.questions);
console.log(webform.getContainer());
OnQuestionValueChanged:onValueChanged(data)
},
});
function onValueChanged(data)
{
if(data.form.questions[0].label === "map"){
//here i wanted to do something like
x = data.form.questions[0].value.x
y = data.form.questions[0].value.y
}
}
Hi
The `onQuestionValueChanged` event should be at the same level of `onFormLoaded`. For example:
let webform = new Survey123Webform({
itemId: '',
onFormLoaded: ()=>{},
onQuestionValueChanged: onValueChanged
})
When you change the value in a map question, it will trigger the onQuestionValueChanged function (e.g. `onValueChanged`) and pass the following data to you which includes x and y.
{
path: ''.
formId: '',
field: '',
value: {
x: 0,
y: 0,
spatialReference: {
wkid: 4326
}
}
}
So your `onValueChanged` function should be:
function onValueChanged(data)
{
x= data.value.x;
y= data.value.y;
}
thanks for the Reply, i tried to write it like
onFormLoaded: ()=>{},
onQuestionValueChanged: onValueChanged
but my onValueChanged will not trigger. thats why i used it like this
OnQuestionValueChanged:onValueChanged(data)
let webform = new Survey123WebForm({
itemId: '',
container: 'test',
clientId: '',
portalUrl: '',
onFormLoaded:(data) =>
{...},
onQuestionValueChanged:onValueChanged
});
function onValueChanged(data)
{
console.log(data);
}