openaustralia/planningalerts

View on GitHub
app/views/applications/_address_field_with_geolocate.html.erb

Summary

Maintainability
Test Coverage
<div x-data="{address: ''}">
  <%= text_field_tag(:q, q, placeholder: "e.g. 1 Sowerby St, Goulburn, NSW 2580", required: "required", class: "address-autocomplete-input", autofocus: true, "x-model.fill": "address") %>
  <% if error %>
    <p class="inline-errors"><%= error %></p>
  <% else %>
    <div x-show="navigator.geolocation" x-data="{
      spinner: false,
      error: '',
      async geolocate(event) {
        this.spinner = true;
        this.error = '';
        try {
          this.address = await getAddress();
          await $nextTick();
          event.target.form.submit();
        } catch(err) {
          this.error = err;
        }
        this.spinner = false;
      }
    }">
      <%= button_tag type: "button", class: "geolocate inline-hints", "@click.prevent": "geolocate($event)" do %>
        &hellip; or locate me automatically
        <%= image_tag("standard/spinner.gif", size: "16x16", "x-show": "spinner", "x-cloak": true) %>
      <% end %>
      <p x-text="error" class="inline-errors"></p>
    </div>
  <% end %>
</div>