I dont know why my Ok and close button is not working in Invalid Data in bootstraps

Viewed 14

I have bootsrap file in twig. I am using php in backend. I want to know why my close and OK.When i fill up form and hit save one dialog will come with invalid address.I am not able to close that using close button and OK button is also not working in that div.button is not working

{% extends container %}

{% block content %}

  {% if error %}
  <div class="row m-t-20">
    <div class="col-md-7">
      <div class="alert alert-danger alert-dismissible" role="alert">{{ error }}</div>
    </div>
  </div>
  {% endif %}

  <form class="form-horizontal general-form" role="form" id="edit_location" method="POST">
  <div class="form-group required">
    <div class="row">
      <div class="col-md-2 col-sm-4">
        <label for="inputOrg" class="control-label">ORG Name</label>
      </div>
      <div class="col-md-5 col-sm-6">
        {{ form.org_name.render }}
      </div>
    </div>
  </div>
  <div class="form-group required">
    <div class="row">
      <div class="col-md-2 col-sm-4">
        <label for="inputUnit" class="control-label">Prac Name</label>
      </div>
      <div class="col-md-5 col-sm-6">
          {{ form.prac_name.render }}
          {{ form.prac_id.render }}
      </div>
      <div class="col-md-3 col-sm-2 p-t-10">
        <a id="show-match-dialog" style="display: none;" data-bind="visible: practiceMatchLink(), click: showLocationMatchDialog"><i class="glyphicon glyphicon-ok"></i> Matched Prac</a>
      </div>
    </div>
  </div>
  <div class="form-group">
    <div class="row">
      <div class="col-md-2 col-sm-4">
        <label for="inputNetwork" class="control-label">Networkbound<br><span class="text-light">(Overrides provider value)</span></label>
      </div>
      <div class="col-md-5 col-sm-6">
        {{ form.networkbound.render }}
        {{ form.network_id.render }}
      </div>
    </div>
  </div>
  <div class="form-group required">
    <div class="row">
      <div class="col-md-2 col-sm-4">
        <label for="inputName" class="control-label">Address</label>
      </div>
      <div class="col-md-5 col-sm-7">
        {{ form.address1.render }}
      </div>
    </div>
  </div>
  <div class="form-group required">
    <div class="row">
      <div class="col-md-2 col-sm-4">
        <label for="inputName" class="control-label">City</label>
      </div>
      <div class="col-md-5 col-sm-7">
        {{ form.city.render }}
      </div>
    </div>
  </div>
  <div class="form-group required">
    <div class="row">
      <div class="col-md-2 col-sm-4">
        <label for="inputName" class="control-label">State</label>
      </div>
      <div class="col-md-5 col-sm-7">
        {{ form.state.render }}
      </div>
    </div>
  </div>
  <div class="form-group required">
    <div class="row">
      <div class="col-md-2 col-sm-4">
        <label for="inputName" class="control-label">ZIP</label>
      </div>
      <div class="col-md-5 col-sm-7">
        {{ form.zip.render }}
      </div>
    </div>
  </div>
{% for item in attributes %}
  <div class="form-group">
    <div class="row">
      <div class="col-md-2 col-sm-4">
        <label for="{{ item.name }}" class="control-label">{{ item.name }}</label>
      </div>
      <div class="col-md-5 col-sm-7">
        <div class="form-group field">
          <input type="text" class="form-control" placeholder="{{ item.name}}" value="{{ item.value }}" name="attribute_{{ item.attributeID }}" id="{{ item.name }}">
        </div>
      </div>
    </div>
  </div>
{% endfor %}
{% if form.insurance_template is defined %}
  <div class="form-group required">
    <div class="row">
      <div class="col-md-2 col-sm-4">
        <label for="insurance_template" class="control-label">Insurance Template</label>
      </div>
      <div class="col-md-5 col-sm-7">
        {{ form.insurance_template.render }}
      </div>
    </div>
  </div>
  <div class="form-group required">
    <div class="row">
      <div class="col-md-2 col-sm-4">
      </div>
      <div class="col-md-5 col-sm-7">
        <div class="error-select" id="error-insurance_template"></div>
      </div>
    </div>
  </div>
{% endif %}

  <div class="form-group required">
    <div class="row">
      <div class="col-md-2 col-sm-4">
        <label for="contact_phone" class="control-label">Phone number</label>
      </div>
      <div class="col-md-5 col-sm-7">
        {{ form.contact_phone.render }}
      </div>
    </div>
  </div>

  <div class="form-group">
    <div class="row">
      <div class="col-md-2 col-sm-4">
        <label for="contact_fax" class="control-label">Fax number</label>
      </div>
      <div class="col-md-5 col-sm-7">
        {{ form.contact_fax.render }}
      </div>
    </div>
  </div>

  <div class="form-group">
    <div class="row">
      <div class="col-md-2 col-sm-4">
        <label for="direct_message_address" class="control-label">Direct message address</label>
      </div>
      <div class="col-md-5 col-sm-7">
        {{ form.direct_message_address.render }}
      </div>
    </div>
  </div>

  <div class="form-group">
    <div class="row">
      <div class="col-md-2 col-sm-4">
        <label for="EMR" class="control-label">EMR</label>
      </div>
      <div class="col-md-5 col-sm-7">
        {{ form.EMR.render }}
      </div>
    </div>
  </div>

  <div class="row m-t-30">
    <div class="col-md-7 col-sm-11">
      <h2>Referral Delivery Preferences</h2>
    </div>
  </div>

  <div class="form-group required">
    <div class="row">
      <div class="col-md-2 col-sm-4">
        <label for="primary_delivery_preference" class="control-label">Delivery Preference</label>
      </div>
      <div class="col-md-5 col-sm-7">
        {{ form.primary_delivery_preference.render }}
      </div>
    </div>
  </div>

  {{ form.list_of_location_ids.render }}
  {{ form.organization_id.render }}
  {{ form.id.render }}

  <div class="form-buttons">
    <button id="save-button" name="continue" type="submit" class="l-inline btn btn-lg btn-default">Save</button>
  </div>
</form>

<div class="modal fade" id="location-match-modal" tabindex="-1" role="dialog" aria-labelledby="saveAsDefaultOutgoingSearch" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title">Matched Practice</h4>
      </div>
      <div class="modal-body">
        <p>By choosing one of the practice names, you will prepopulate the fields in the form  Note that any existing fields will be overwritten.</p>

        <div style="max-height: 300px; overflow-y: auto;">
          <table class="table m-t-30">
            <thead>
              <tr>
                <th>Address</th>
                <th>City, State</th>
                <th>Zip</th>
                <th>Phone</th>
                <th>Fax</th>
              </tr>
            </thead>
            <tbody data-bind="foreach: matchedLocations">
              <tr>
                <td>
                  <div><a href="#" data-bind="text: address1, click: $parent.selectLocationToPrepopulate"></a></div>
                </td>
                <td><span data-bind="text: city"></span>, <span data-bind="text: state"></span></td>
                <td data-bind="text: zip"></td>
                <td data-bind="text: phone"></td>
                <td data-bind="text: fax"></td>
              </tr>
            </tbody>
          </table>
        </div>
      </div>
      <div class="modal-footer text-center">
        <button type="button" class="btn btn-lg btn-white" data-dismiss="modal">Cancel</button>
      </div>
    </div>
  </div>
</div>

<div class="modal fade" id="invalid-address-modal" tabindex="-1" role="dialog" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title">Invalid Address</h4>
      </div>
      <div class="modal-body">
        <p>
          The address provided did not geolocate properly.
          Please try a different address.
        </p>
      </div>
      <div class="modal-footer text-center">
        <button type="button" class="l-inline btn btn-lg btn-default btn-white" data-dismiss="modal">OK</button>
      </div>
    </div>
  </div>
</div>

<div class="modal fade" id="multiple-addresses-modal" tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="false">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title">Multiple Addresses Found</h4>
      </div>
      <div class="modal-body">
        <p class="m-b-10">
          The address provided returned more than one result.  Please
          choose the best option to use for the provider's location.
          If none of the options available are acceptable, please contact
          an administrator.
        </p>

        <div id="geolocated-addresses"></div>
      </div>
      <div class="modal-footer text-center">
        <button type="button" class="btn btn-lg btn-white" data-dismiss="modal">OK</button>
      </div>
    </div>
  </div>
</div>

<div id="geolocator-on" style="display: none;">{{ geolocator_on }}</div>

{% endblock %}

{% block page_js %}
  {% javascripts 'js/autocomplete.js'
  'js/autocomplete_sources.js'
  'js/admin/provider/location-update.js'

  output='compiled/js/admin-provider-location-edit.js'
 %}
  <script type="text/javascript" src="{{ assets(asset_url) }}"></script>
  {% endjavascripts %}
{% endblock %}

I have attached my js file also

$(function() {
  var LocationUpdate = function() {
    var self = this;

    self.action = ko.observableArray();
    self.insuranceName = ko.observable();
    self.practiceMatchLink = ko.observable(false);
    self.locationMatchModal = $('#location-match-modal').modal({show: false});
    self.invalidAddressModal = $('#invalid-address-modal').modal({show: false});
    self.multipleAddressesModal = $('#multiple-addresses-modal').modal({show: false});
    self.geocodedResults = [];

    self.initialAddress1 = $('#address1').val();
    self.initialCity = $('#city').val();
    self.locationId = ko.observable($('#id').val());

    self.orgId = ko.observable($('#organization_id').val());
    self.orgName = ko.observable($('#organization_name').val());
    window.organizationObejct.setOrg(self.orgId());

    self.practiceId = ko.observable($('#practice_id').val());
    self.practiceName = ko.observable($('#practice_name').val());

    self.networkId = ko.observable($('#network_id').val());
    self.networkName = ko.observable($('#network').val());

    self.matchedLocations = ko.observableArray([]);

    $('#contact_email').attr('type', 'email');

    self.organizationAutocomplete = {
      source: window.fetchOrganizations,
      response: function(event, ui) {
        if (ui.item == null) {
          self.orgId(null);
          window.organizationObejct.setOrg(self.orgId());
          self.clearPractice()
        }
        self.orgName($('#organization_name').val() );
      },
      onItemSelected: function(event, ui) {
        self.orgName(ui.item.label);
        self.orgId(ui.item.value);
        window.organizationObejct.setOrg(self.orgId());
        self.clearPractice();
      },
      onItemChanged: function(event, ui) {
        if (ui.item == null) {
          self.orgId(null)
          window.organizationObejct.setOrg(self.orgId());
          self.clearPractice();
        }
      }
    };

    self.clearPractice = function() {
      self.practiceId(null);
      self.practiceMatchLink(false);
      $('#practice_id').val('');
    }

    self.networkAutocomplete = {
      source: window.fetchNetworks,
      onItemSelected: function(event, ui) {
        self.networkId (ui.item.value);
        self.networkName (ui.item.label);
        $('#network_id').val(self.networkId());
      },
      onItemChanged: function(event, ui) {
        if (ui.item === null) {
          self.networkId(null);
          self.networkName(null);
          $('#network_id').val('');
        }
      }
    };

    self.practiceAutocomplete = {
      source : window.fetchPractices,
      response: function(event, ui) {
          self.practiceMatchLink(false);
      },
      onItemSelected: function(event, ui) {
          self.practiceId (ui.item.value);
          self.practiceName (ui.item.label);
          self.practiceMatchLink(true);
          $('#practice_id').val(self.practiceId());
      },
      onItemChanged: function(event, ui) {
          if (ui.item == null) {
              self.practiceId(null);
              self.practiceMatchLink(false);
              $('#practice_id').val('');
          }
      }
    };

    self.validatedAddress = false;
    self.checkGeocoding = function() {

      if ($('#geolocator-on').text() == 'false') {
        return true;
      }

      if (self.validatedAddress) {
        return true;
      }

      var url = urls.ajax('location/get-geocode-results');

      var params = {
        'address1': $('#address1').val(),
        'city': $('#city').val(),
        'state': $('#state').val(),
        'zip': $('#zip').val()
      };

      $.post(url, params, function(result) {
        self.geocodedResults = result.data;

        if (result.data.length < 1) {
          self.invalidAddressModal.modal('show');
          return false;
        } else if (result.data.length == 1) {
          self.validatedAddress = true;
          var loc = result.data[0];
          $('#address1').val(loc.address);
          $('#city').val(loc.city);
          $('#state').val(loc.state).change();
          $('#zip').val(loc.zip);
          $('#edit_location').submit();
        } else {
          self.showMultipleAddressPossibiliesDialog();
          return false;
        }
      }, 'json');
    };

    var editLocationValidator = formJQueryValidate({
      formSelector: '#edit_location',
      ignore: 'radio',
      rules: {
        "speciality_name" : {
          validateAutocomplete: { "selector_uuid": "#speciality_uuid", "selector_text": "#speciality_name" }
        },
        "contact_phone": {
          validatePhoneExt: { "value": $('#contact_phone').val() },
          validatePhone: { "value": $('#contact_phone').val() }
        },
        "contact_fax": {
          validatePhoneExt: { "value": $('#contact_fax').val() },
          validateFax: { "value": $('#contact_fax').val() },
          FieldValueDependentNotEmpty: {
            "fieldValue": '#primary_delivery_preference',
            "requiredValue": "Fax"
          }
        },
        "zip": {
          validateZIP: { "value": $('#zip').val() }
        },
        "direct_message_address": {
          realEmail: true,
          FieldValueDependentNotEmpty: {
            "fieldValue": '#primary_delivery_preference',
            "requiredValue": "Direct Message"
          }
        },
        "EMR": {
          FieldValueDependentNotEmpty: {
            "fieldValue": '#primary_delivery_preference',
            "requiredValue": "EMR"
          }
        }
      },
      messages: {
        "direct_message_address": {
          FieldValueDependentNotEmpty: "This field is required because of Delivery Preference."
        },
        "contact_fax": {
          FieldValueDependentNotEmpty: "This field is required because of Delivery Preference."
        },
        "EMR": {
          FieldValueDependentNotEmpty: "This field is required because of Delivery Preference."
        }
      },
      errorPlacement: function(error, element) {
        if (typeof $(element).data('bind') !== 'undefined' && $(element).data('bind').indexOf('fbSelect:{}') !== -1) {
          error.insertAfter($(element).siblings('.bootstrap-select'));
        }
      },
      submitHandler: self.checkGeocoding
    });

    self.showLocationMatchDialog = function() {
      self.matchedLocations([]);
      var url = urls.ajax('location/search');
      $.getJSON(url, {filter: self.practiceName(), page_size: 25, deleted_dt: true}, function(result) {
        for (i in result.data) {
          self.matchedLocations.push({
            'address1': result.data[i].address1,
            'city': result.data[i].city,
            'state': result.data[i].state,
            'zip': result.data[i].zip,
            'phone': result.data[i].phone,
            'fax': result.data[i].fax
          });
        }
      }).success(function() {
        self.locationMatchModal.modal('show');
      });
    };

    self.selectLocationToPrepopulate = function() {
      $('#address1').val(this.address1);
      $('#city').val(this.city);
      $('#state').val(this.state).change();
      $('#zip').val(this.zip);
      $('#contact_phone').val(this.phone);
      $('#contact_fax').val(this.fax);
      self.locationMatchModal.modal('hide');
    };

    self.buildMatchedLocationsList = function(response){
      $('#locations_list').empty()
      for(i in response.locations){
        //Do not show the same practice location that we are already on
        if(self.locationId() != response.locations[i].id){
          var tr = document.createElement('tr');
          var td_input = document.createElement('td');
          var td_label = document.createElement('td');

          var checkbox = document.createElement('input');
          var description = document.createTextNode(
              response.locations[i].first_name + ' ' +  response.locations[i].last_name + ' - ' +
              response.locations[i].practice_name + ' - ' +
              response.locations[i].address1 + ' ' +
              response.locations[i].city + ' ' +
              response.locations[i].state + ' ' +
              response.locations[i].zip
          );

          checkbox.type = 'checkbox';
          checkbox.value = response.locations[i].id;
          checkbox.name = 'location_checkboxes';
          checkbox.id = 'checkbox_' + response.locations[i].id;

          td_input.appendChild(checkbox);
          td_label.appendChild(description);

          $(td_input).css('vertical-align','top');
          $(td_label).css('padding','0px 5px');

          tr.appendChild(td_input);
          tr.appendChild(td_label);
          $('#locations_list').append(tr);
        }
      }
      $('#locations_list').parent().scrollTop;
    };

    self.showMultipleAddressPossibiliesDialog = function() {
      $('#geolocated-addresses').html('');

      var ret = '';
      for (var i = 0; i < self.geocodedResults.length; i++) {
        var row = self.geocodedResults[i];
        ret += '<div class="row">';
          ret += '<div class="col-md-4 text-right"><strong>Address:</strong></div>';
          ret += '<div class="col-md-8">' + row.address + '</div>';
        ret += '</div>';

        ret += '<div class="row">';
          ret += '<div class="col-md-4 text-right"><strong>City:</strong></div>';
          ret += '<div class="col-md-8">' + row.city + '</div>';
        ret += '</div>';

        ret += '<div class="row">';
          ret += '<div class="col-md-4 text-right"><strong>State:</strong></div>';
          ret += '<div class="col-md-8">' + row.state + '</div>';
        ret += '</div>';

        ret += '<div class="row m-b-10">';
          ret += '<div class="col-md-4 text-right"><strong>Zip:</strong></div>';
          ret += '<div class="col-md-8">' + row.zip + '</div>';
        ret += '</div>';
        
        ret += '<div class="row m-b-30">';
          ret += '<div class="col-md-8 col-md-offset-4">';
            ret += '<button id="choose-address-' + i.toString() + '" class="choose-address btn btn-lg btn-blue">Use this Address</button></div>';
          ret += '</div>';
        ret += '</div>';
      }

      $('#geolocated-addresses').html(ret);
      self.multipleAddressesModal.modal('show');
    };

    $('#multiple-addresses-modal').on('hidden.bs.modal', function () {
      $('#save-button').attr('disabled', false);
    });


   /* $('#invalid-address-modal').on('hidden.bs.modal', function () {
      $('#save-button').attr('disabled', false);
    });
*/

    // this will submit the form
    $(document).on('click', '.choose-address', function() {
      var index = parseInt($(this).attr('id').replace('choose-address-', ''));
      var loc = self.geocodedResults[index];
      $('#address1').val(loc.address);
      $('#city').val(loc.city);
      $('#state').val(loc.state);
      $('#zip').val(loc.zip);
      self.validatedAddress = true;
      $('#edit_location').submit();
    });
  };

  window.page = new LocationUpdate();
  ko.applyBindings(window.page, document.getElementById('content'));

});

0 Answers
Related