Loading…
Tilbage

Profilbillede

Prefill autocomplete component

Sandra Lilieholm

Hi

I have just started to use the dawa compenent and it works except for prefillind the field. In some cases we already know the address of the user and want it to be prefilled, if the user chooses he can change it.

Preferably I want the select event to trigger when it has been prefilled to get the address data and handle validation the same way as if the user select the address.

 

Is there a good way to prefill the component with the adress?
Is there a way to programmatically trigger the select event?

Best regards
Sandra Lilieholm

Hi Sandra,

Sorry for the late answer.

The component currently does not handle the scenario you describe.

Triggering the select event would probably not work well. If the address is incorrect or has changed, a select would open the list of selections, which is not very sutiable behavior when prefilling.

I would suggest the following:

If you have the ID of the address, I would fetch the address from the API and simply enter the text into the input field without triggering the select event. No validation is necessary in this case.

If you do not have the ID of the address, I would use the "datavask" API to retrieve the correct address text to insert into the input field. If the address is not valid (the API indicates if it is), the user has to enter a new one anyway, so in this case it is probably best to just leave it empty.