Hi @yisrael-wix ,
I am working on developing a support page for my website where individuals can upload there “support need” and they provide the first four digits of their UK postcode, The postcode is then converted in to an address string that is returned once they click the postcode-click button.
It all seems to work well, except when I am trying to save the data via code to the collection? the collection doesn’t recognise the data as an address string or format and this then creates the need for me to convert it manually within the dataset when wanting to apply it to a map. This is obviously time consuming if I receive many support requests.
I provide the code below, If there is a way to via code to confirm that the value is an address string before saving then that would be amazing.
export function saveDetails_click(event) {
let supRef = $w("#supportRef").value;
if (supRef.length === 0) {
$w("#text53").show();
} else {
let supportRef = $w("#supportRef").value;
let name = $w("#input3").value;
let indigroup = $w("#radioGroup1").value;
let volpaid = $w("#radioGroup9").value;
let description = $w("#textBox1").value;
let address = $w("#input4").value;
let email = $w("#input5").value;
let spoc = $w("#input6").value;
let phone = $w("#input7").value;
let dateStart = $w("#datePicker1").value;
let dateEnd = $w("#datePicker2").value;
let monday = $w("#radioGroup2").value;
let tuesday = $w("#radioGroup3").value;
let wednesday = $w("#radioGroup4").value;
let thursday = $w("#radioGroup5").value;
let friday = $w("#radioGroup6").value;
let saturday = $w("#radioGroup7").value;
let sunday = $w("#radioGroup8").value;
let toSave = {
"reference": supportRef,
"name": name,
"descriptionOfNeed": description,
"contactEmail": email,
"singlePointOfContact": spoc,
"phoneNumber": phone,
"postcode": address,
"startDate": dateStart,
"endDate": dateEnd,
"individualOrOrganisation": indigroup,
"paidOrVoluntary": volpaid,
"monday": monday,
"tuesday": tuesday,
"wednesday": wednesday,
"thursday": thursday,
"friday": friday,
"saturday": saturday,
"sunday": sunday
};
wixData.save("helpNeeded", toSave)
.then(() => {
$w("#text52").show();
$w("#slideshow1").changeSlide(3);
$w("#dynamicDataset").refresh();
})
.catch((err) => {
let errorMsg = err;
$w("#text53").show();
});
}
}
export function postcodeClick_click(event) {
let postcode = $w("#input4").value;
let apiUrl = "https://api.postcodes.io/postcodes?q=" + postcode;
if (postcode.length < 5) {
fetch(apiUrl, { method: 'get' })
.then((httpResponse) => {
if (httpResponse.ok) {
console.log("httpResponse")
return httpResponse.json();
} else {
return console.log("fetch did not succeed")
}
})
.then((json) => {
var myArr = json.result[0];
var location = (myArr.parish + "," + myArr.admin_district + "," + myArr.outcode + "," + "UK");
$w("#input4").value = location;
})
.catch((err) => {
console.log(err);
});
}
}
Hi @ simon.adams
I’m not realy good with json, but it might be something else.
so can you tell what the console logs whowed?
greets
Kristof.
Hi Kristof,
The Console logs the response from the fetch call found below:
I am using myArr to get the details from an array of about 10 lists of details found below.
I then use “myArr. parliamentary_constituency” for example to get “Poole”,
The issue is that it is seemingly wanting me to use the “address input” and a google API to be able to input an address but I want to do it this way for a number of reasons.
httpResponse
{…}
postcode: “BH15 1AA”
quality: 1
eastings: 401109
northings: 90659
country: “England”
nhs_ha: “South West”
longitude: -1.985656
latitude: 50.71556
european_electoral_region: “South West”
primary_care_trust: “Bournemouth and Poole Teaching”
region: “South West”
lsoa: “Poole 015F”
msoa: “Poole 015”
incode: “1AA”
outcode: “BH15”
parliamentary_constituency: “Poole”
admin_district: “Bournemouth, Christchurch and Poole”
parish: “Bournemouth, Christchurch and Poole, unparished area”
admin_county: null
admin_ward: “Poole Town”
ced: null
ccg: “NHS Dorset”
nuts: “Bournemouth and Poole”
codes:
{…}
admin_district: “E06000058”
admin_county: “E99999999”
admin_ward: “E05012674”
parish: “E43000261”
parliamentary_constituency: “E14000881”
ccg: “E38000045”
ccg_id: “11J”
ced: “E99999999”
nuts: “UKK21”
First off, please take note of the forum guidelines and use tags appropriately.
Use Tags Properly. You can only @ tag Wix Community Managers & Corvid Masters—NOT Wix employees.
As for using the Address Input, it will only work with a Google API key as stated in the Wix pages for it and you can simply connect it to a dataset to save the values received from it.
https://www.wix.com/corvid/reference/$w.AddressInput.html
AddressInput
An element for entering addresses.
AddressInput lets users type an address, and suggests exact locations using Google Maps services.
Note
To connect an AddressInput with Google Maps addresses, you must register for a Google Maps API key .
https://support.wix.com/en/article/adding-and-setting-up-an-address-input-element
https://support.wix.com/en/article/generating-a-google-maps-api-key-for-the-address-input-element
If you are wanting to use postcode.io own JSON HTTP API for this, then you might be better off using another input method like a text box or a rich text box.
Finally, to add address for a user, then make sure it is as stated in the docs.
https://www.wix.com/corvid/reference/wix-users-backend.html#Address
I think that you are expecting it to be saved as in Wix Stores and have the whole address saved in one go.
https://www.wix.com/corvid/reference/wix-stores-backend.html#Address
Hi Gos,
I went through the piece where it says “ask a question of the community”, so I thought I could ask a question of a specific individual in the community or what is the point of having individual profiles?
In relation to your answer, I have read the documentation that you are pointing too.
I do not wish to use a google API as there is a charge for doing so and what I am doing is on a not for profit basis.
I just want to be able to save information from a text input element in the correct format within the dataset, which is an address, which I can then link to the maps from the dataset, I do not see why this has to go through a Google Maps API.
I am not doing this for the Wix Stores because I am not shipping individuals, I am using it to create a Map of where there are support needs within the UK and have a second map with locations of volunteers and I am just trying to make it easier to locate and support individuals within these current difficult times as coordination is one of the key things that needs to happen to make sure individuals are best supported and at speed.
Best wishes,
Simon