Sha256: 98cbf3d9a924eabcdcdd5f4ba131e4b37ac7b388fe81abb9652c9a7e86f548eb

Contents?: true

Size: 1.7 KB

Versions: 10

Compression:

Stored size: 1.7 KB

Contents

.row.address-fields
  = form.hidden_field :egov_identifier
  .col-6
    = form.text_field :street
  .col-3
    = form.text_field :house_number
  .col-3
    = form.text_field :orientation_number
  .col-12
    = form.text_field :city
    = form.text_field :postcode
    = form.select :district, EgovUtils::Address.districts.collect{|r| [r[:name],r[:name]]}
    = form.select :region, EgovUtils::Address.regions.collect{|r| [r[:name],r[:name]]}
    -# form.text_field :country
    %div.validation-button
      = link_to t('label_find'), 'javascript:void(0)', class: 'btn btn-secondary address-validator-btn'

:javascript
  $(function(){
    $('.address-validator-btn').not('.validator-initialized').on('click', function(evt) {
      var values = {},
          $fields = $(this).closest('.address-fields');

      $fields.find(':input').each(function(i){
        var name,
            name_m = $(this).attr('name').match(/\[([^\[]*)\]$/);
        name = name_m[1];
        values[name] = $(this).val();
      });
      $.ajax('#{egov_utils.validate_ruian_path}', {
        method: 'GET',
        dataType: 'json',
        data: {
          address: values
        }
      }).done(function(json){
        var field;
        for( var key in json ) {
          field = $fields.find("[name$='["+key+"]']");
          if( field.length !== 1 || !json[key] )
            continue;
          field.val(json[key]);
        }
      }).fail(function(xhr, status, errorMsg){
        $('#modal').modal('hide');
        eGovUtilities.showModal(xhr.responseJSON.error, {modalId: 'modalAlert', backdrop: 'static'}).on('hidden.bs.modal', function(){
          $('#modal').modal('show');
        });
      });
    }).addClass('.validator-initialized');
  });

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
egov_utils-0.1.14 app/views/egov_utils/addresses/_form.html.haml
egov_utils-0.1.13 app/views/egov_utils/addresses/_form.html.haml
egov_utils-0.1.12 app/views/egov_utils/addresses/_form.html.haml
egov_utils-0.1.11 app/views/egov_utils/addresses/_form.html.haml
egov_utils-0.1.10 app/views/egov_utils/addresses/_form.html.haml
egov_utils-0.1.9 app/views/egov_utils/addresses/_form.html.haml
egov_utils-0.1.8 app/views/egov_utils/addresses/_form.html.haml
egov_utils-0.1.7 app/views/egov_utils/addresses/_form.html.haml
egov_utils-0.1.6 app/views/egov_utils/addresses/_form.html.haml
egov_utils-0.1.5 app/views/egov_utils/addresses/_form.html.haml